From: Stas Shtin Date: Sat, 10 Apr 2010 11:08:56 +0000 (+0400) Subject: Added django application and a sample project for running in web server X-Git-Url: https://vcs.maemo.org/git/?p=ipypbx;a=commitdiff_plain;h=9a7deb8eb4dbd2aaeeb95d043703429489946a17 Added django application and a sample project for running in web server --- diff --git a/ipypbx.pro b/ipypbx.pro deleted file mode 100644 index f529326..0000000 --- a/ipypbx.pro +++ /dev/null @@ -1,3 +0,0 @@ -SOURCES = ui/layout.ui -TRANSLATIONS = src/ipypbx/locale/ipypbx_ru.ts src/ipypbx/locale/ipypbx_fi.ts - diff --git a/projects/ipypbx.pro b/projects/ipypbx.pro new file mode 100644 index 0000000..f529326 --- /dev/null +++ b/projects/ipypbx.pro @@ -0,0 +1,3 @@ +SOURCES = ui/layout.ui +TRANSLATIONS = src/ipypbx/locale/ipypbx_ru.ts src/ipypbx/locale/ipypbx_fi.ts + diff --git a/projects/sample/__init__.py b/projects/sample/__init__.py new file mode 100644 index 0000000..78d5397 --- /dev/null +++ b/projects/sample/__init__.py @@ -0,0 +1,16 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . diff --git a/projects/sample/local_settings.py.template b/projects/sample/local_settings.py.template new file mode 100644 index 0000000..81dbb51 --- /dev/null +++ b/projects/sample/local_settings.py.template @@ -0,0 +1,80 @@ +# Django settings for sample project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + ('Stas Shtin', 'stas@example.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. +DATABASE_NAME = '/home/antisvin/.ipypbx/ipypbx.db' # Or path to database file if using sqlite3. +DATABASE_USER = '' # Not used with sqlite3. +DATABASE_PASSWORD = '' # Not used with sqlite3. +DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. +DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Europe/Moscow' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/media/' + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'm%j*u3=&^oj*o&lfdsr0q)!83%=)op-ruc%i#q@ccoet0nhgj3' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', +# 'django.template.loaders.eggs.load_template_source', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +) + +ROOT_URLCONF = 'sample.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.admindocs', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', +) diff --git a/projects/sample/manage.py b/projects/sample/manage.py new file mode 100755 index 0000000..7fb9044 --- /dev/null +++ b/projects/sample/manage.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . + +from django.core.management import execute_manager +try: + import settings # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.exit(1) + +if __name__ == "__main__": + execute_manager(settings) diff --git a/projects/sample/settings.py b/projects/sample/settings.py new file mode 100644 index 0000000..3b57beb --- /dev/null +++ b/projects/sample/settings.py @@ -0,0 +1,87 @@ +# Django settings for sample project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. +DATABASE_NAME = '' # Or path to database file if using sqlite3. +DATABASE_USER = '' # Not used with sqlite3. +DATABASE_PASSWORD = '' # Not used with sqlite3. +DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. +DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/Chicago' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/media/' + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'm%j*u3=&^oj*o&lfdsr0q)!83%=)op-ruc%i#q@ccoet0nhgj3' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', +# 'django.template.loaders.eggs.load_template_source', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +) + +ROOT_URLCONF = 'sample.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.admindocs', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', +) + +try: + from local_settings import * +except ImportError: + print ("Copy local_settings.py.template to local_settings.py and " + "customize it before running IPyPBX web interface.") + raise diff --git a/projects/sample/urls.py b/projects/sample/urls.py new file mode 100644 index 0000000..b84a38d --- /dev/null +++ b/projects/sample/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls.defaults import * + +from django.contrib import admin +admin.autodiscover() + +urlpatterns = patterns( + '', + (r'^admin/doc/', include('django.contrib.admindocs.urls')), + (r'^admin/', include(admin.site.urls)), + (r'', include('ipypbxweb.urls')), +) diff --git a/src/ipypbxweb/__init__.py b/src/ipypbxweb/__init__.py new file mode 100644 index 0000000..78d5397 --- /dev/null +++ b/src/ipypbxweb/__init__.py @@ -0,0 +1,16 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . diff --git a/src/ipypbxweb/admin.py b/src/ipypbxweb/admin.py new file mode 100644 index 0000000..3e87933 --- /dev/null +++ b/src/ipypbxweb/admin.py @@ -0,0 +1,24 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . + +from django.contrib import admin +from ipypbxweb import models + + +for model in (models.Connection, models.SipProfile, models.Domain, + models.Gateway, models.Endpoint, models.Extension): + admin.site.register(model) diff --git a/src/ipypbxweb/models.py b/src/ipypbxweb/models.py new file mode 100644 index 0000000..fe6a5eb --- /dev/null +++ b/src/ipypbxweb/models.py @@ -0,0 +1,77 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . + +from django.db import models + + +class Connection(models.Model): + """ + Connection to a freeswitch server. + """ + name = models.CharField(max_length=100) + local_ip_address = models.IPAddressField() + local_port = models.PositiveIntegerField() + freeswitch_ip_address = models.IPAddressField() + freeswitch_port = models.PositiveIntegerField() + + +class SipProfile(models.Model): + connection = models.ForeignKey(Connection) + name = models.CharField(max_length=100) + external_rtp_ip = models.CharField(max_length=100) + external_sip_ip = models.CharField(max_length=100) + rtp_ip = models.CharField(max_length=100) + sip_ip = models.CharField(max_length=100) + sip_port = models.PositiveIntegerField() + accept_blind_registration = models.BooleanField() + authenticate_calls = models.BooleanField() + is_active = models.BooleanField() + + +class Domain(models.Model): + sip_profile = models.ForeignKey(SipProfile) + host_name = models.CharField(max_length=100) + is_active = models.BooleanField() + + +class Gateway(models.Model): + sip_profile = models.ForeignKey(SipProfile) + name = models.CharField(max_length=100) + username = models.CharField(max_length=100) + password = models.CharField(max_length=100) + realm = models.CharField(max_length=100) + from_domain = models.CharField(max_length=100) + expire_in_seconds = models.PositiveIntegerField() + retry_in_seconds = models.PositiveIntegerField() + caller_id_in_from_field = models.BooleanField() + is_active = models.BooleanField() + + +class Endpoint(models.Model): + user_id = models.CharField(max_length=100) + password = models.CharField(max_length=100) + domain = models.CharField(max_length=100) + is_active = models.BooleanField() + + +class Extension(models.Model): + destination_match = models.CharField(max_length=100) + xml_dialplan = models.TextField() + domain = models.CharField(max_length=100) + endpoint = models.ForeignKey(Endpoint) + authenticate_calls = models.BooleanField() + is_active = models.BooleanField() diff --git a/src/ipypbxweb/tests.py b/src/ipypbxweb/tests.py new file mode 100644 index 0000000..8594801 --- /dev/null +++ b/src/ipypbxweb/tests.py @@ -0,0 +1,40 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . + +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/src/ipypbxweb/views.py b/src/ipypbxweb/views.py new file mode 100644 index 0000000..78d5397 --- /dev/null +++ b/src/ipypbxweb/views.py @@ -0,0 +1,16 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see .