[Checkins] SVN: Products.SQLAlchemyDA/trunk/ - better error handling for the ZMI screens

Andreas Jung andreas at andreas-jung.com
Thu Jun 7 04:22:05 EDT 2007


Log message for revision 76443:
  - better error handling for the ZMI screens
  - SQL test tab
  

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

-=-
Modified: Products.SQLAlchemyDA/trunk/CHANGES.txt
===================================================================
--- Products.SQLAlchemyDA/trunk/CHANGES.txt	2007-06-06 21:33:29 UTC (rev 76442)
+++ Products.SQLAlchemyDA/trunk/CHANGES.txt	2007-06-07 08:22:03 UTC (rev 76443)
@@ -1,7 +1,11 @@
-0.2.2 (unreleased)
+0.3.0 (unreleased)
 
     - fixed some security assertions
 
+    - added Test tab for executing SQL queries directly
+
+    - better error handling for ZMI screens
+
 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-06 21:33:29 UTC (rev 76442)
+++ Products.SQLAlchemyDA/trunk/da.py	2007-06-07 08:22:03 UTC (rev 76443)
@@ -41,9 +41,9 @@
     """ A shim around z3c.sqlalchemy implementing something DA-ish """
 
     manage_options = ({'label' : 'Info', 'action' : 'manage_workspace'},) +\
+                     ({'label' : 'Test', 'action' : 'manage_test'},) + \
                      PropertyManager.manage_options + \
                      SimpleItem.manage_options
-
     _properties = (
         {'id' : 'sqlalchemy_wrapper_name', 'type' : 'selection', 'mode' : 'rw', 
          'select_variable' : 'registeredWrappers'},
@@ -68,7 +68,10 @@
 
     @property
     def _wrapper(self):
-        return getSAWrapper(self.sqlalchemy_wrapper_name)
+        try:
+            return getSAWrapper(self.sqlalchemy_wrapper_name)
+        except ValueError:
+            return None
 
 
     security.declareProtected(view, 'getMapper')
@@ -92,11 +95,16 @@
     security.declareProtected(view_management_screens, 'getInfo')
     def getInfo(self):
         """ return a dict with additional information """
-        d = self._wrapper.kw
-        d['DSN'] = self._wrapper.dsn
-        return d
 
+        wrapper = self._wrapper
+        if wrapper is not None:
+            d = self._wrapper.kw
+            d['DSN'] = self._wrapper.dsn
+            return d
+        else:
+            return {}
 
+
     def _typesMap(self, proxy):
         """ Obtain types map from the underlying DB-API. I
             hope that is portable code.
@@ -219,6 +227,12 @@
             msg = 'Database connections closed'
             RESPONSE.redirect(self.absolute_url() + '/manage_workspace?manage_tabs_message=%s' % msg)
 
+
+    security.declareProtected(view_management_screens, 'manage_doQuery')
+    def manage_doQuery(self, query):
+        """ perform a query through the ZMI"""
+        return self.query(query)
+
     
     security.declareProtected(view_management_screens, 'getVersion')
     def getVersion(self):
@@ -229,6 +243,9 @@
     manage_workspace = PageTemplateFile('pt/info', 
                                         globals(), 
                                         __name__='manage_workspace')
+    manage_test = PageTemplateFile('pt/query', 
+                                        globals(), 
+                                        __name__='manage_test')
 
 InitializeClass(SAWrapper)
 

Modified: Products.SQLAlchemyDA/trunk/pt/info.zpt
===================================================================
--- Products.SQLAlchemyDA/trunk/pt/info.zpt	2007-06-06 21:33:29 UTC (rev 76442)
+++ Products.SQLAlchemyDA/trunk/pt/info.zpt	2007-06-07 08:22:03 UTC (rev 76443)
@@ -1,43 +1,54 @@
 <div tal:replace="structure context/manage_page_header" />
 <div tal:replace="structure context/manage_tabs" />
 
-<table class="info" 
-       tal:define="info_d context/getInfo">
-    <tbody>
-        <tr>
-            <td class="form-label">Name</td>
-            <td class="list-item" tal:content="context/getId" />
-        </tr>
+<tal:def tal:define="info_d context/getInfo">
 
-        <tr>
-            <td class="form-label">Connection pool size</td>
-            <td class="list-item" tal:content="context/getPoolSize" />
-        </tr>
+    <div tal:condition="not: info_d">
+        No database connection configured! Go to the <em>Properties</em> tab in order to change the configuration.       
+    </div>
+    
+    <tal:if condition="info_d">
 
-        <tr>
-            <td class="form-label">Number of open connections</td>
-            <td class="list-item" tal:content="context/getCheckedin" />
-        </tr>
-        <tr>
-            <td class="form-label">Connected</td>
-            <td class="list-item" tal:content="context/connected" />
-        </tr>
+        <table class="info" >
+            <tbody>
+                <tr>
+                    <td class="form-label">Name</td>
+                    <td class="list-item" tal:content="context/getId" />
+                </tr>
 
-        <tr tal:repeat="k info_d">
-            <td class="form-label" tal:content="k"/>
-            <td class="list-item" tal:content="info_d/?k" />
-        </tr>
-    </tbody>
-</table>
+                <tr>
+                    <td class="form-label">Connection pool size</td>
+                    <td class="list-item" tal:content="context/getPoolSize" />
+                </tr>
 
-<form action="manage_stop" method="POST" tal:condition="context/connected">
-    <input type="submit" value="Close connections"/> 
-</form>
+                <tr>
+                    <td class="form-label">Number of open connections</td>
+                    <td class="list-item" tal:content="context/getCheckedin" />
+                </tr>
+                <tr>
+                    <td class="form-label">Connected</td>
+                    <td class="list-item" tal:content="context/connected" />
+                </tr>
 
-<form action="manage_start" method="POST" tal:condition="not: context/connected">
-    <input type="submit" value="Open connections"/> 
-</form>
+                <tr tal:repeat="k info_d">
+                    <td class="form-label" tal:content="k"/>
+                    <td class="list-item" tal:content="info_d/?k" />
+                </tr>
+            </tbody>
+        </table>
 
+        <form action="manage_stop" method="POST" tal:condition="context/connected">
+            <input type="submit" value="Close connections"/> 
+        </form>
+
+        <form action="manage_start" method="POST" tal:condition="not: context/connected">
+            <input type="submit" value="Open connections"/> 
+        </form>
+
+    </tal:if>
+
+</tal:def>
+
 <hr>
 <div style="font-size: 80%; text-align: center" >
 Written by Andreas Jung for <a href="http://www.zopyx.com">ZOPYX Ltd. & Co. KG</a>, D-72070 T&uuml;bingen, Germany.

Added: Products.SQLAlchemyDA/trunk/pt/query.zpt
===================================================================
--- Products.SQLAlchemyDA/trunk/pt/query.zpt	                        (rev 0)
+++ Products.SQLAlchemyDA/trunk/pt/query.zpt	2007-06-07 08:22:03 UTC (rev 76443)
@@ -0,0 +1,56 @@
+<div tal:replace="structure context/manage_page_header" />
+<div tal:replace="structure context/manage_tabs" />
+
+<tal:def tal:define="info_d context/getInfo">
+
+    <div tal:condition="not: info_d">
+        No database connection configured! Go to the <em>Properties</em> tab in order to change the configuration.       
+    </div>
+
+    <fieldset tal:condition="info_d">
+        <legend>Test a query</legend>
+
+        <form action="manage_test" method="post">
+            <textarea name="query" rows="5" cols="60"><span tal:replace="request/query | nothing"/></textarea>
+            <br/>
+            <input type="submit" value="Execute query" />
+        </form>
+    </fieldset>
+
+    <fieldset id="resultset" tal:condition="request/query | nothing">
+        <legend>Resultset</legend>
+
+        <tal:def define="result python: context.manage_doQuery(request.query)">
+            <div tal:condition="not: result">
+                Empty resultset returned
+            </div>
+
+            <table tal:condition="result" border="1">
+                <thead>
+                    <tr> 
+                        <th tal:repeat="item python: result[0]"
+                            span tal:content="item/name" 
+                        />
+                    </tr>
+                </thead>
+                <tbody>
+                    <tr tal:repeat="row python: result[1]">
+                        <td tal:repeat="item row"
+                            span tal:content="item" 
+                        />
+                    </tr>
+                </tbody>
+            </table>
+        </tal:def>
+    </fieldset>
+
+</tal:def>
+
+<hr/>
+<div style="font-size: 80%; text-align: center" >
+Written by Andreas Jung for <a href="http://www.zopyx.com">ZOPYX Ltd. & Co. KG</a>, D-72070 T&uuml;bingen, Germany.
+<br>
+SQLAlchemyDA <span tal:replace="context/getVersion"/> is published under the Zope Public License ZPL 2.1.
+</div>
+
+<div tal:replace="structure context/manage_page_footer" />

Modified: Products.SQLAlchemyDA/trunk/version.txt
===================================================================
--- Products.SQLAlchemyDA/trunk/version.txt	2007-06-06 21:33:29 UTC (rev 76442)
+++ Products.SQLAlchemyDA/trunk/version.txt	2007-06-07 08:22:03 UTC (rev 76443)
@@ -1 +1 @@
-0.2.2
+0.3.0



More information about the Checkins mailing list