From d81069667080c8cb0b1a0c88be54a49ed8faa7b9 Mon Sep 17 00:00:00 2001 From: Stas Shtin Date: Sat, 10 Apr 2010 15:55:39 +0400 Subject: [PATCH] Make IPyPBX work with SQL tables created by django models --- .gitignore | 5 ++ projects/sample/local_settings.py.template | 12 ----- projects/sample/settings.py | 1 + src/.gitignore | 3 -- src/ipypbx/controllers.py | 2 +- src/ipypbx/create.sql | 68 ++++++++++++++++++++++++ src/ipypbx/main.py | 15 ++++-- src/ipypbx/models.py | 79 ---------------------------- 8 files changed, 87 insertions(+), 98 deletions(-) create mode 100644 .gitignore delete mode 100644 src/.gitignore create mode 100644 src/ipypbx/create.sql delete mode 100644 src/ipypbx/models.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46ab091 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*~ +*.pyc +local_settings.py +.#* +*# diff --git a/projects/sample/local_settings.py.template b/projects/sample/local_settings.py.template index 81dbb51..86d78d4 100644 --- a/projects/sample/local_settings.py.template +++ b/projects/sample/local_settings.py.template @@ -11,10 +11,6 @@ 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 @@ -70,11 +66,3 @@ TEMPLATE_DIRS = ( # 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/settings.py b/projects/sample/settings.py index 3b57beb..551294d 100644 --- a/projects/sample/settings.py +++ b/projects/sample/settings.py @@ -77,6 +77,7 @@ INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', + 'ipypbxweb' ) try: diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index eef29c1..0000000 --- a/src/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*~ -*.pyc - diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py index 3263273..4ea7394 100644 --- a/src/ipypbx/controllers.py +++ b/src/ipypbx/controllers.py @@ -47,7 +47,7 @@ class BaseController(QtCore.QObject): # Otherwise initialize a new model. else: self.model = QtSql.QSqlTableModel(parent) - self.model.setTable(self.basename + 's') + self.model.setTable('ipypbxweb_%s' % self.basename) # Create model header from fields list. for i, field in enumerate(self.fields): diff --git a/src/ipypbx/create.sql b/src/ipypbx/create.sql new file mode 100644 index 0000000..4c95e8e --- /dev/null +++ b/src/ipypbx/create.sql @@ -0,0 +1,68 @@ +BEGIN; +CREATE TABLE "ipypbxweb_connection" ( + "id" integer NOT NULL PRIMARY KEY, + "name" varchar(100) NOT NULL, + "local_ip_address" char(15) NOT NULL, + "local_port" integer unsigned NOT NULL, + "freeswitch_ip_address" char(15) NOT NULL, + "freeswitch_port" integer unsigned NOT NULL +) +; +CREATE TABLE "ipypbxweb_sipprofile" ( + "id" integer NOT NULL PRIMARY KEY, + "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"), + "name" varchar(100) NOT NULL, + "external_rtp_ip" varchar(100) NOT NULL, + "external_sip_ip" varchar(100) NOT NULL, + "rtp_ip" varchar(100) NOT NULL, + "sip_ip" varchar(100) NOT NULL, + "sip_port" integer unsigned NOT NULL, + "accept_blind_registration" bool NOT NULL, + "authenticate_calls" bool NOT NULL, + "is_active" bool NOT NULL +) +; +CREATE TABLE "ipypbxweb_domain" ( + "id" integer NOT NULL PRIMARY KEY, + "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"), + "host_name" varchar(100) NOT NULL, + "is_active" bool NOT NULL +) +; +CREATE TABLE "ipypbxweb_gateway" ( + "id" integer NOT NULL PRIMARY KEY, + "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"), + "name" varchar(100) NOT NULL, + "username" varchar(100) NOT NULL, + "password" varchar(100) NOT NULL, + "realm" varchar(100) NOT NULL, + "from_domain" varchar(100) NOT NULL, + "expire_in_seconds" integer unsigned NOT NULL, + "retry_in_seconds" integer unsigned NOT NULL, + "caller_id_in_from_field" bool NOT NULL, + "is_active" bool NOT NULL +) +; +CREATE TABLE "ipypbxweb_endpoint" ( + "id" integer NOT NULL PRIMARY KEY, + "user_id" varchar(100) NOT NULL, + "password" varchar(100) NOT NULL, + "domain" varchar(100) NOT NULL, + "is_active" bool NOT NULL +) +; +CREATE TABLE "ipypbxweb_extension" ( + "id" integer NOT NULL PRIMARY KEY, + "destination_match" varchar(100) NOT NULL, + "xml_dialplan" text NOT NULL, + "domain" varchar(100) NOT NULL, + "endpoint_id" integer NOT NULL REFERENCES "ipypbxweb_endpoint" ("id"), + "authenticate_calls" bool NOT NULL, + "is_active" bool NOT NULL +) +; +CREATE INDEX "ipypbxweb_sipprofile_connection_id" ON "ipypbxweb_sipprofile" ("connection_id"); +CREATE INDEX "ipypbxweb_domain_sip_profile_id" ON "ipypbxweb_domain" ("sip_profile_id"); +CREATE INDEX "ipypbxweb_gateway_sip_profile_id" ON "ipypbxweb_gateway" ("sip_profile_id"); +CREATE INDEX "ipypbxweb_extension_endpoint_id" ON "ipypbxweb_extension" ("endpoint_id"); +COMMIT; diff --git a/src/ipypbx/main.py b/src/ipypbx/main.py index 626f527..2c6876b 100644 --- a/src/ipypbx/main.py +++ b/src/ipypbx/main.py @@ -17,7 +17,7 @@ import os import sys -from ipypbx import controllers, sql, ui +from ipypbx import controllers, ui from PyQt4 import QtCore, QtGui, QtSql @@ -48,9 +48,18 @@ def setupDb(prefix=PREFIX, dbname=DB_NAME): if db.open(): if created: - for query in sql.creation_queries: - QtSql.QSqlQuery().exec_(query) + # Load script from local file. + sql_script = open(os.path.join(os.path.dirname(__file__), 'create.sql')).read() + + # Split into individual queries. + sql_queries = sql_script.split(';') + + # Execute all queries except BEGIN/COMMIT sequences. + query = QtSql.QSqlQuery() + for query_string in sql_queries[1:-2]: + query.exec_(query_string) else: + # Something went horribly wrong. QtGui.QMessageBox.warning( None, "Fatal Error", "Database Error: %s" % db.lastError().text()) sys.exit(1) diff --git a/src/ipypbx/models.py b/src/ipypbx/models.py deleted file mode 100644 index 68f9a5b..0000000 --- a/src/ipypbx/models.py +++ /dev/null @@ -1,79 +0,0 @@ -# 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 WILL BE DELETED SOON - -from axiom.item import Item -from axiom.attributes import boolean, integer, reference, text - - -class Connection(Item): - name = text() - local_ip_address = text() - local_port = integer() - freeswitch_ip_address = text() - freeswitch_port = integer() - - -class SipProfile(Item): - connection = reference() - name = text() - external_rtp_ip = text() - external_sip_ip = text() - rtp_ip = text() - sip_ip = text() - sip_port = integer() - accept_blind_registration = boolean() - authenticate_calls = boolean() - is_active = boolean() - - -class Domain(Item): - sip_profile = reference() - host_name = text() - is_active = boolean() - - -class Gateway(Item): - sip_profile = reference() - name = text() - username = text() - password = text() - realm = text() - from_domain = text() - expire_in_seconds = integer() - retry_in_seconds = integer() - caller_id_in_from_field = boolean() - is_active = boolean() - - -class Endpoint(Item): - user_id = text() - password = text() - domain = text() - is_active = boolean() - - -class Extension(Item): - destination_match = text() - xml_dialplan = text() - domain = text() - endpoint = reference() - authenticate_calls = boolean() - is_active = boolean() - -- 1.7.9.5