From 95c6139fc97e9b456f37699571b1e6b827149dc1 Mon Sep 17 00:00:00 2001 From: Stas Shtin Date: Sun, 11 Apr 2010 23:39:31 +0400 Subject: [PATCH] Mark headers for translation --- src/ipypbx/controllers.py | 115 ++++++++++++++++++++++++++++----------------- src/ipypbx/create.sql | 8 ++++ src/ipypbxweb/models.py | 4 ++ 3 files changed, 83 insertions(+), 44 deletions(-) diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py index a196a27..de4674e 100644 --- a/src/ipypbx/controllers.py +++ b/src/ipypbx/controllers.py @@ -28,7 +28,8 @@ class BaseController(QtCore.QObject): fields = () view_list_fields = () view_display_fields = () - view_display_fields_hidden = () + view_display_fields_hidden = 'ID', 'Connection ID' + is_bound_to_connection = True def __init__(self, model=None, view_list=None, view_display=None, parent=None, views=None): super(BaseController, self).__init__(parent=parent) @@ -53,7 +54,10 @@ class BaseController(QtCore.QObject): # Create model header from fields list. for i, field in enumerate(self.fields): self.model.setHeaderData( - i, QtCore.Qt.Horizontal, QtCore.QVariant(field)) + i, QtCore.Qt.Horizontal, + QtCore.QVariant(QtGui.QApplication.translate( + "MainWindow", field, None, + QtGui.QApplication.UnicodeUTF8))) # Fetch model data. self.model.select() @@ -77,6 +81,8 @@ class BaseController(QtCore.QObject): self.view_list.resizeColumnsToContents() self.view_list.resizeRowsToContents() self.view_list.horizontalHeader().setStretchLastSection(True) + + # Select first row. self.view_list.selectRow(0) # Are we given an existing view display? @@ -89,7 +95,10 @@ class BaseController(QtCore.QObject): # If view_display_fields is not send, display all fields except # the first one that is usually the ID. - display_fields = self.getDisplayFields() + display_fields = [ + field for field in self.fields if not field in + self.view_display_fields_hidden] + for i, field in enumerate(self.fields): if field in display_fields: field_widget = self.getFieldWidget(field) @@ -108,30 +117,6 @@ class BaseController(QtCore.QObject): QtCore.QObject.connect( sender, QtCore.SIGNAL(signal), receiver, QtCore.SLOT(slot)) - - def getDisplayFields(self): - """ - Return the list of fields to display. - - If it's not set explicitly, use all defined fields except the first - which usually is the primary key. - """ - # Do we have the fields to display explicitly set? - if self.view_display_fields: - fields = self.view_display_fields - else: - # Do we have hidden fields set? - if self.view_display_fields_hidden: - hidden = self.view_display_fields_hidden - # If not, hide the first one. - else: - hidden = self.fields[0] - - # Filter away all hidden fields. - fields = [field for field in self.fields if not field in hidden] - - return fields - def getFieldWidget(self, field): """ Return widget for given field name. @@ -172,7 +157,8 @@ class BaseController(QtCore.QObject): # Clear all displayed fields. for field in self.getDisplayFields(): - self.getFieldWidget(field).clear() + if hasattr(field, 'clear'): + self.getFieldWidget(field).clear() def save(self): """ @@ -182,7 +168,9 @@ class BaseController(QtCore.QObject): # on its own. self.view_display.submit() self.getFieldWidget('Add').setEnabled(True) - + + def update(self): + pass class ConnectionController(BaseController): @@ -190,8 +178,12 @@ class ConnectionController(BaseController): Connections controller. """ fields = ( - 'ID', 'Name', 'Local IP Address', 'Local Port', - 'Freeswitch IP Address', 'Freeswitch Port') + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Local IP Address'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Local Port'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Freeswitch IP Address'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Freeswitch Port')) view_list_fields = 'Name', 'Freeswitch IP Address', 'Freeswitch Port' def clone(self): @@ -201,23 +193,36 @@ class ConnectionController(BaseController): This creates a new connection with bound data copied from another one. """ + class SipProfileController(BaseController): """ SIP Profile controller. """ fields = ( - 'ID', 'Connection ID', 'Name', 'External RTP IP', 'External SIP IP', - 'RTP IP', 'SIP IP', 'SIP Port', 'Accept Blind Registration', - 'Authenticate Calls', 'Is Active') + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'External RTP IP'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'External SIP IP'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'RTP IP'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP IP'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Port'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Accept Blind Registration'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Authenticate Calls'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active')) view_list_fields = 'Name', 'SIP IP', 'SIP Port' - view_display_fields_hidden = 'ID', 'Connection ID' - + class DomainController(BaseController): """ Domain controller. """ - fields = 'ID', 'SIP Profile ID', 'Host Name', 'Is Active' + fields = ( + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Profile ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Host Name'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active')) view_list_fields = 'SIP Profile ID', 'Host Name', 'Is Active' @@ -226,9 +231,18 @@ class GatewayController(BaseController): Gateway controller. """ fields = ( - 'ID', 'SIP Profile ID', 'Name', 'Username', 'Password', 'Realm', - 'From Domain', 'Expire In Seconds', 'Retry In Seconds', - 'Caller ID In From Field', 'Is Active') + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Profile ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Username'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Password'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Realm'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'From Domain'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Expire In Seconds'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Retry In Seconds'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Caller ID In From Field'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active')) view_list_fields = 'SIP Profile ID', 'Name' @@ -236,15 +250,28 @@ class EndpointController(BaseController): """ Endpoint controller. """ - fields = 'ID', 'User ID', 'Password', 'Domain ID', 'Is Active' - + fields = ( + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'User ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Password'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Domain ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active')) + view_list_fields = 'User ID', 'Password', 'Domain ID' + class ExtensionController(BaseController): """ Extension controller. """ fields = ( - 'ID', 'Destination Match', 'XML Dialplan', 'Domain ID', 'Endpoint ID', - 'Authenticate Calls', 'Is Active') + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Destination Match'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'XML Dialplan'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Domain ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Endpoint ID'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Authenticate Calls'), + QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active')) view_list_fields = 'Destination Match', 'Domain ID', 'Endpoint ID' diff --git a/src/ipypbx/create.sql b/src/ipypbx/create.sql index e913aba..a2a8e3e 100644 --- a/src/ipypbx/create.sql +++ b/src/ipypbx/create.sql @@ -23,6 +23,7 @@ CREATE TABLE "ipypbxweb_sipprofile" ( ; CREATE TABLE "ipypbxweb_domain" ( "id" integer NOT NULL PRIMARY KEY, + "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"), "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"), "host_name" varchar(100) NOT NULL, "is_active" bool NOT NULL @@ -30,6 +31,7 @@ CREATE TABLE "ipypbxweb_domain" ( ; CREATE TABLE "ipypbxweb_gateway" ( "id" integer NOT NULL PRIMARY KEY, + "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"), "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"), "name" varchar(100) NOT NULL, "username" varchar(100) NOT NULL, @@ -44,6 +46,7 @@ CREATE TABLE "ipypbxweb_gateway" ( ; CREATE TABLE "ipypbxweb_endpoint" ( "id" integer NOT NULL PRIMARY KEY, + "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"), "user_id" varchar(100) NOT NULL, "password" varchar(100) NOT NULL, "domain_id" integer NOT NULL REFERENCES "ipypbxweb_domain" ("id"), @@ -52,6 +55,7 @@ CREATE TABLE "ipypbxweb_endpoint" ( ; CREATE TABLE "ipypbxweb_extension" ( "id" integer NOT NULL PRIMARY KEY, + "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"), "destination_match" varchar(100) NOT NULL, "xml_dialplan" text NOT NULL, "domain_id" integer NOT NULL REFERENCES "ipypbxweb_domain" ("id"), @@ -61,8 +65,12 @@ CREATE TABLE "ipypbxweb_extension" ( ) ; CREATE INDEX "ipypbxweb_sipprofile_connection_id" ON "ipypbxweb_sipprofile" ("connection_id"); +CREATE INDEX "ipypbxweb_domain_connection_id" ON "ipypbxweb_domain" ("connection_id"); CREATE INDEX "ipypbxweb_domain_sip_profile_id" ON "ipypbxweb_domain" ("sip_profile_id"); +CREATE INDEX "ipypbxweb_gateway_connection_id" ON "ipypbxweb_gateway" ("connection_id"); CREATE INDEX "ipypbxweb_gateway_sip_profile_id" ON "ipypbxweb_gateway" ("sip_profile_id"); +CREATE INDEX "ipypbxweb_endpoint_connection_id" ON "ipypbxweb_endpoint" ("connection_id"); CREATE INDEX "ipypbxweb_endpoint_domain_id" ON "ipypbxweb_endpoint" ("domain_id"); +CREATE INDEX "ipypbxweb_extension_connection_id" ON "ipypbxweb_extension" ("connection_id"); CREATE INDEX "ipypbxweb_extension_domain_id" ON "ipypbxweb_extension" ("domain_id"); CREATE INDEX "ipypbxweb_extension_endpoint_id" ON "ipypbxweb_extension" ("endpoint_id"); \ No newline at end of file diff --git a/src/ipypbxweb/models.py b/src/ipypbxweb/models.py index 7a944d8..75266a5 100644 --- a/src/ipypbxweb/models.py +++ b/src/ipypbxweb/models.py @@ -43,12 +43,14 @@ class SipProfile(models.Model): class Domain(models.Model): + connection = models.ForeignKey(Connection) sip_profile = models.ForeignKey(SipProfile) host_name = models.CharField(max_length=100) is_active = models.BooleanField() class Gateway(models.Model): + connection = models.ForeignKey(Connection) sip_profile = models.ForeignKey(SipProfile) name = models.CharField(max_length=100) username = models.CharField(max_length=100) @@ -62,6 +64,7 @@ class Gateway(models.Model): class Endpoint(models.Model): + connection = models.ForeignKey(Connection) user_id = models.CharField(max_length=100) password = models.CharField(max_length=100) domain = models.ForeignKey(Domain) @@ -69,6 +72,7 @@ class Endpoint(models.Model): class Extension(models.Model): + connection = models.ForeignKey(Connection) destination_match = models.CharField(max_length=100) xml_dialplan = models.TextField() domain = models.ForeignKey(Domain) -- 1.7.9.5