[Checkins] SVN: Products.SQLAlchemyDA/trunk/ - getting rid of SA wrapper registry

Andreas Jung andreas at andreas-jung.com
Thu Jun 7 05:28:29 EDT 2007


Log message for revision 76448:
  - getting rid of SA wrapper registry
  - configure the database connection directly by specifying its DSN
  
  

Changed:
  U   Products.SQLAlchemyDA/trunk/CHANGES.txt
  U   Products.SQLAlchemyDA/trunk/da.py
  U   Products.SQLAlchemyDA/trunk/pt/query.zpt

-=-
Modified: Products.SQLAlchemyDA/trunk/CHANGES.txt
===================================================================
--- Products.SQLAlchemyDA/trunk/CHANGES.txt	2007-06-07 09:08:38 UTC (rev 76447)
+++ Products.SQLAlchemyDA/trunk/CHANGES.txt	2007-06-07 09:28:28 UTC (rev 76448)
@@ -6,6 +6,9 @@
 
     - better error handling for ZMI screens
 
+    - no longer depending on a pre-registered SQLAlchemy wrapper. SQLAlchemyDA
+      now accepts as any other DA a DSN as propertiy 'dsn'
+
 0.2.1 (06.05.2007)
 
     - connections can be closed/opened through the ZMI

Modified: Products.SQLAlchemyDA/trunk/da.py
===================================================================
--- Products.SQLAlchemyDA/trunk/da.py	2007-06-07 09:08:38 UTC (rev 76447)
+++ Products.SQLAlchemyDA/trunk/da.py	2007-06-07 09:28:28 UTC (rev 76448)
@@ -8,6 +8,7 @@
 
 import os
 import logging
+import random
 import time
 
 from Globals import InitializeClass
@@ -17,7 +18,7 @@
 from OFS.PropertyManager import PropertyManager
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
-from z3c.sqlalchemy import allSAWrapperNames, getSAWrapper
+from z3c.sqlalchemy import getSAWrapper, createSAWrapper
 
 
 LOG = logging.getLogger('SQLAlchemyDA')
@@ -45,13 +46,13 @@
                      PropertyManager.manage_options + \
                      SimpleItem.manage_options
     _properties = (
-        {'id' : 'sqlalchemy_wrapper_name', 'type' : 'selection', 'mode' : 'rw', 
-         'select_variable' : 'registeredWrappers'},
+        {'id' : 'dsn', 'type' : 'string', 'mode' : 'rw', },
         {'id' : 'title', 'type' : 'string', 'mode' : 'rw'}, 
     )
 
+
     meta_type = 'SQLAlchemyDA '
-    sqlalchemy_wrapper_name = None
+    dsn = ''
     _isAnSQLConnection = True
 
     security = ClassSecurityInfo()
@@ -59,19 +60,16 @@
     def __init__(self, id, title=''):
         self.id = id
         self.title = title
+        self.util_id = '%s.%s' % (time.time(), random.random())
 
-
-    security.declareProtected(view_management_screens, 'registeredWrappers')
-    def registeredWrappers(self):
-        """ return a list of registered wrapper names """
-        return allSAWrapperNames()      
-
     @property
     def _wrapper(self):
-        try:
-            return getSAWrapper(self.sqlalchemy_wrapper_name)
-        except ValueError:
-            return None
+        if self.dsn:
+            try:
+                return getSAWrapper(self.dsn)
+            except ValueError:               
+                return createSAWrapper(self.dsn, forZope=True, name=self.util_id)
+        return None
 
 
     security.declareProtected(view, 'getMapper')
@@ -106,8 +104,8 @@
 
 
     def _typesMap(self, proxy):
-        """ Obtain types map from the underlying DB-API. I
-            hope that is portable code.
+        """ Obtain types map from the underlying DB-API. I hope
+            that is portable code.
         """
 
         if not hasattr(self, '_v_types_map'):
@@ -239,6 +237,14 @@
         """ return version.txt """
         return open(os.path.join(os.path.dirname(__file__), 'version.txt')).read()
 
+
+    security.declareProtected(view_management_screens, 'manage_editProperties')
+    def manage_editProperties(self, REQUEST):
+        """ Intercept changed properties in order to perform 
+            further actions.
+        """
+        return PropertyManager.manage_editProperties(self, REQUEST)
+
  
     manage_workspace = PageTemplateFile('pt/info', 
                                         globals(), 

Modified: Products.SQLAlchemyDA/trunk/pt/query.zpt
===================================================================
--- Products.SQLAlchemyDA/trunk/pt/query.zpt	2007-06-07 09:08:38 UTC (rev 76447)
+++ Products.SQLAlchemyDA/trunk/pt/query.zpt	2007-06-07 09:28:28 UTC (rev 76448)
@@ -35,9 +35,9 @@
                 </thead>
                 <tbody>
                     <tr tal:repeat="row python: result[1]">
-                        <td tal:repeat="item row"
-                            span tal:content="item" 
-                        />
+                        <td tal:repeat="item row">
+                            <span tal:replace="item" />&nbsp;
+                        </td>
                     </tr>
                 </tbody>
             </table>



More information about the Checkins mailing list