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

Philipp von Weitershausen philikon at philikon.de
Fri Feb 20 14:42:42 EST 2004


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

Added Files:
      Tag: philikon-movecontent-branch
	__init__.py add.pt configure.zcml edit.pt sqlscript.py test.pt 
	testresults.pt tests.py 
Log Message:
SQLScript moved to zope.app 


=== Added File Zope3/src/zope/app/sqlscript/browser/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/sqlscript/browser/add.pt ===
<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>


=== Added File Zope3/src/zope/app/sqlscript/browser/configure.zcml ===
<configure
    xmlns='http://namespaces.zope.org/zope'
    xmlns:browser='http://namespaces.zope.org/browser'
    i18n_domain='zope'
    >

  <browser:addMenuItem
      title="SQLScript"
      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>

</configure>


=== Added File Zope3/src/zope/app/sqlscript/browser/edit.pt ===
<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>


=== Added File Zope3/src/zope/app/sqlscript/browser/sqlscript.py ===
##############################################################################
#
# 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: sqlscript.py,v 1.1.2.1 2004/02/20 19:42:41 philikon Exp $
"""

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()


=== Added File Zope3/src/zope/app/sqlscript/browser/test.pt ===
<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>


=== Added File Zope3/src/zope/app/sqlscript/browser/testresults.pt ===
<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>


=== Added File Zope3/src/zope/app/sqlscript/browser/tests.py ===
##############################################################################
#
# 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: tests.py,v 1.1.2.1 2004/02/20 19:42:41 philikon Exp $
"""
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