Make IPyPBX work with SQL tables created by django models
authorStas Shtin <antisvin@gmail.com>
Sat, 10 Apr 2010 11:55:39 +0000 (15:55 +0400)
committerStas Shtin <antisvin@gmail.com>
Sat, 10 Apr 2010 11:55:39 +0000 (15:55 +0400)
.gitignore [new file with mode: 0644]
projects/sample/local_settings.py.template
projects/sample/settings.py
src/.gitignore [deleted file]
src/ipypbx/controllers.py
src/ipypbx/create.sql [new file with mode: 0644]
src/ipypbx/main.py
src/ipypbx/models.py [deleted file]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..46ab091
--- /dev/null
@@ -0,0 +1,5 @@
+*~
+*.pyc
+local_settings.py
+.#*
+*#
index 81dbb51..86d78d4 100644 (file)
@@ -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',
-)
index 3b57beb..551294d 100644 (file)
@@ -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 (file)
index eef29c1..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-*~
-*.pyc
-
index 3263273..4ea7394 100644 (file)
@@ -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 (file)
index 0000000..4c95e8e
--- /dev/null
@@ -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;
index 626f527..2c6876b 100644 (file)
@@ -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 (file)
index 68f9a5b..0000000
+++ /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 <http://www.gnu.org/licenses/>.
-
-
-# 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()
-