[Zope3-checkins] CVS: Zope3/src/zope/app/sqlscript/browser - __init__.py:1.2 add.pt:1.2 configure.zcml:1.2 edit.pt:1.2 sqlscript.py:1.2 test.pt:1.2 testresults.pt:1.2 tests.py:1.2

Philipp von Weitershausen philikon at philikon.de
Tue Feb 24 11:51:10 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/sqlscript/browser
In directory cvs.zope.org:/tmp/cvs-serv27095/src/zope/app/sqlscript/browser

Added Files:
	__init__.py add.pt configure.zcml edit.pt sqlscript.py test.pt 
	testresults.pt tests.py 
Log Message:


Moved the SQL Script content type into its own package below zope.app,
including browser views and interfaces. Also, separated out the DTML
directives into their own module, zope.app.sqlscript.dtml, so they can
more easily be reused independently.




=== Zope3/src/zope/app/sqlscript/browser/__init__.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/__init__.py	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/sqlscript/browser/add.pt 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/add.pt	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,17 @@
+<html metal:use-macro="context/@@standard_macros/page">
+
+  <head>
+    <title>SQL Script</title>
+  </head>
+  <body>
+ 
+    <div metal:fill-slot="body">
+        
+       <div metal:use-macro="view/generated_form/macros/body">
+            <input type="submit" value="Add and Test" 
+                  metal:fill-slot="extra_buttons" name="add_test" />
+       </div>
+   </div>
+  </body>
+
+</html>


=== Zope3/src/zope/app/sqlscript/browser/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/configure.zcml	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,76 @@
+<configure
+    xmlns='http://namespaces.zope.org/zope'
+    xmlns:browser='http://namespaces.zope.org/browser'
+    i18n_domain='zope'
+    >
+
+  <browser:addMenuItem
+      title="SQL Script"
+      description="A content-based script to execute dyanmic SQL."
+      class="zope.app.sqlscript.SQLScript"
+      permission="zope.ManageContent"   
+      view="zope.app.sqlscript.SQLScript"
+      /> 
+
+  <browser:addform
+      schema="zope.app.sqlscript.interfaces.ISQLScript"
+      label="Add a SQL Script"
+      content_factory=".sqlscript.SQLScript"
+      keyword_arguments="connectionName source arguments"
+      name="zope.app.sqlscript.SQLScript"
+      permission="zope.ManageContent"
+      template="add.pt"
+      class=".sqlscript.SQLScriptAdd"
+      /> 
+
+  <browser:editform
+      schema="zope.app.sqlscript.interfaces.ISQLScript"
+      name="edit.html"
+      menu="zmi_views"
+      label="Edit an SQL script"
+      permission="zope.ManageContent"
+      template="edit.pt"
+      class=".sqlscript.SQLScriptEdit" 
+      />
+
+  <browser:pages
+      for="zope.app.sqlscript.interfaces.ISQLScript"
+      permission="zope.View"
+      class=".sqlscript.SQLScriptTest" >
+
+    <browser:page
+        name="test.html"
+        template="test.pt" 
+        menu="zmi_views"
+        title="[test-page-title] Test"
+        />
+    <browser:page
+        name="testResults.html"
+        template="testresults.pt"
+        />
+
+  </browser:pages>
+
+  <browser:pages
+      for="zope.app.sqlscript.interfaces.ISQLScript"
+      permission="zope.ManageBindings"
+      class="zope.app.browser.cache.cacheable.CacheableView"
+      >
+
+    <browser:page
+        name="Caching.html"
+        attribute="form"  
+        menu="zmi_views" title="Caching"
+        />
+    <browser:page
+        name="ChangeCaching.html"
+        attribute="action"
+        />
+    <browser:page
+        name="InvalidateCache.html"
+        attribute="invalidate"
+        />
+
+  </browser:pages>
+
+</configure>


=== Zope3/src/zope/app/sqlscript/browser/edit.pt 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/edit.pt	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,17 @@
+<html metal:use-macro="context/@@standard_macros/page">
+
+  <head>
+    <title>SQL Script</title>
+  </head>
+  <body>
+ 
+    <div metal:fill-slot="body">
+        
+       <div metal:use-macro="view/generated_form/macros/body">
+            <input type="submit" value="Change and Test" 
+                  metal:fill-slot="extra_buttons" name="change_test" />
+       </div>
+   </div>
+  </body>
+
+</html>


=== Zope3/src/zope/app/sqlscript/browser/sqlscript.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/sqlscript.py	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,203 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""SQL Script Views
+
+$Id$
+"""
+
+from zope.app.browser.form.add import AddView
+from zope.app.browser.form.submit import Update
+from zope.app.interfaces.rdb import DatabaseException
+from zope.app.interfaces.container import IAdding
+from zope.app import zapi
+
+from zope.app.sqlscript.sqlscript import SQLScript
+from zope.app.sqlscript.interfaces import ISQLScript
+
+__metaclass__ = type
+
+class SQLScriptTest:
+    """Test the SQL inside the SQL Script
+    """
+
+    __used_for__ = ISQLScript
+
+    error = None
+
+    def getArguments(self):
+        form = self.request.form
+        arguments = {}
+
+        for argname, argvalue in self.context.getArguments().items():
+            value = form.get(argname)
+            if value is None:
+                value = argvalue.get('default')
+            if value is not None:
+                arguments[argname.encode('UTF-8')] = value
+        return arguments
+
+    def getTestResults(self):
+        try:
+            return self.context(**self.getArguments())
+        except (DatabaseException, AttributeError, Exception), error:
+            self.error = error
+            return []
+
+    def getFormattedError(self):
+        error = str(self.error)
+        return error
+
+    def getRenderedSQL(self):
+        return self.context.getTemplate()(**self.getArguments())
+
+class SQLScriptAdd:
+    """Provide interface to add SQL Script
+    """
+
+    def update(self):
+        """Set the Update variable for Add and Test
+        >>> from zope.publisher.browser import TestRequest
+
+        >>> rqst = TestRequest()
+        >>> class Base(object):
+        ...     def __init__(self, request):
+        ...         self.request = request
+        ...     def update(self):
+        ...         self.updated = True
+
+        >>> class V(SQLScriptAdd, Base):
+        ...     pass
+
+        >>> dc = V(rqst)
+        >>> dc.update()
+        >>> dc.updated
+        True
+        >>> 'UPDATE_SUBMIT' in rqst
+        False
+        >>> d = {'add_test': True}
+        >>> rqst1 = TestRequest(form = d)
+        >>> dc1 = V(rqst1)
+        >>> dc1.update()
+        >>> 'UPDATE_SUBMIT' in rqst1
+        True
+        """
+        if 'add_test' in self.request:
+            self.request.form[Update] = ''
+
+        return super(SQLScriptAdd, self).update()
+
+    def nextURL(self):
+        """
+        >>> from zope.publisher.browser import TestRequest
+        >>> from zope.app.tests.placelesssetup import setUp, tearDown
+        >>> setUp()
+        >>> rqst = TestRequest()
+        >>> class Base(object):
+        ...     def __init__(self, request):
+        ...         self.request = request
+        ...         self.context = self
+        ...         self.contentName = 'new srcipt'
+        ...     def __getitem__(self, key):
+        ...         return None
+        ...     def nextURL(self):
+        ...         return "www.zeomega.com"
+        
+        >>> class V(SQLScriptAdd, Base):
+        ...     pass
+        >>> 
+        >>> rqst = TestRequest()
+        >>> dc = V(rqst)
+        >>> dc.nextURL()
+        'www.zeomega.com'
+        >>> d = {'add_test': True}
+        >>> rqst1 = TestRequest(form = d)
+        >>> dc1 = V(rqst1)
+        >>> dc1.nextURL()
+        'http://127.0.0.1/test.html'
+        """
+        if 'add_test' in self.request:
+            name = self.context.contentName
+            container = self.context.context
+            obj = container[name]
+            url = zapi.getView(obj, 'absolute_url', self.request)()
+            url = '%s/test.html' % url
+            return url
+        else:
+            return super(SQLScriptAdd, self).nextURL()
+
+class SQLScriptEdit:
+    """Provide interface to Edit and Test  SQL Script
+    """        
+
+    def update(self):
+        """Set the Update variable for Change and Test
+        >>> from zope.publisher.browser import TestRequest
+        
+        >>> rqst = TestRequest()
+        >>> class Base(object):
+        ...     def __init__(self, request):
+        ...         self.request = request
+        ...         self.errors  = ('no errors')
+        ...     def update(self):
+        ...         self.updated = True
+        ...         return "update returned"
+
+        >>> class V(SQLScriptEdit, Base):
+        ...     pass
+
+        >>> dc = V(rqst)
+        >>> dc.update()
+        'update returned'
+        >>> dc.updated
+        True
+        >>> 'UPDATE_SUBMIT' in rqst
+        False
+        >>>
+        
+
+        >>> d = {'change_test': True}
+        >>> rqst1 = TestRequest(form = d)
+        >>> dc1 = V(rqst1)
+        >>> dc1.errors = ()
+        >>> dc1.update()
+        'update returned'
+        >>> 'UPDATE_SUBMIT' in rqst1
+        True
+        >>> dc1.updated
+        True
+        >>> rqst1.response.getHeader('location')
+        'test.html'
+        >>> rqst1.response.getStatus()
+        302
+           
+        >>> d = {'change_test': True}
+        >>> rqst2 = TestRequest(form = d)
+        >>> dc2 = V(rqst2)
+        >>> dc2.errors = ('errorname', 1234)
+        >>> dc2.update()
+        'update returned'
+        >>> 'UPDATE_SUBMIT' in rqst2
+        True
+        >>> rqst2.response.getHeader('location')
+        
+        >>> rqst2.response.getStatus()
+        599
+        """
+        if 'change_test' in self.request:
+            self.request.form[Update] = ''
+            super(SQLScriptEdit, self).update()
+            if not self.errors:
+                url = 'test.html'
+                self.request.response.redirect(url)
+        return super(SQLScriptEdit, self).update()


=== Zope3/src/zope/app/sqlscript/browser/test.pt 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/test.pt	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,38 @@
+<html metal:use-macro="views/standard_macros/page">
+<body>
+
+<div metal:fill-slot="body">
+<form action="." method="post">
+
+  <pre tal:content="context/source" />
+
+  <table border="1"
+      tal:define="args context/getArguments"
+      tal:condition="args">
+    <tbody>
+      <tr>
+        <th i18n:translate="">Argument Name</th>
+        <th i18n:translate="">Type</th>
+        <th i18n:translate="">Value</th>
+      </tr>
+
+      <tr tal:repeat="arg python: args.keys()">
+        <td tal:content="arg"></td>
+        <td tal:content="python: args[arg].get('type')"> </td>
+        <td><input type="text" name="" size="10" value=""
+                tal:attributes="value python: args[arg].get('default');
+                                name arg"/></td>
+      </tr>
+
+
+    </tbody>
+  </table>
+
+  <input type="submit" name="testResults.html:method" value="Test"
+         i18n:attributes="value test-button"/>
+
+</form>
+</div>
+
+</body>
+</html>


=== Zope3/src/zope/app/sqlscript/browser/testresults.pt 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/testresults.pt	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,35 @@
+<html metal:use-macro="views/standard_macros/page">
+<body>
+
+<div metal:fill-slot="body">
+
+  <pre tal:content="view/getRenderedSQL" />
+
+  <table border="1" cellspacing="0" cellpadding="2"
+      tal:define="result view/getTestResults"
+      tal:condition="result">
+    <tbody>
+
+      <tr>
+        <th tal:repeat="field result/columns"
+            tal:content="field">Field Name</th>
+      </tr>
+
+      <tr tal:repeat="row result">
+        <td tal:repeat="field result/columns"
+            tal:content="python: getattr(row, field)">Value</td>
+      </tr>
+
+
+    </tbody>
+  </table>
+
+  <tal:block tal:condition="view/error">
+    <h3 i18n:translate="">An Error occurred</h3>
+    <pre tal:content="view/getFormattedError" />
+  </tal:block>
+
+</div>
+
+</body>
+</html>


=== Zope3/src/zope/app/sqlscript/browser/tests.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:51:10 2004
+++ Zope3/src/zope/app/sqlscript/browser/tests.py	Tue Feb 24 11:50:37 2004
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""DTML Page Evaluation Tests
+
+$Id$
+"""
+import unittest, doctest
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocTestSuite('zope.app.sqlscript.browser.sqlscript'),
+        ))
+    
+if __name__ == '__main__': unittest.main()




More information about the Zope3-Checkins mailing list