[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser - SQLScriptEdit.py:1.1 SQLScriptTest.py:1.1 __init__.py:1.1 configure.zcml:1.1 edit.pt:1.1 test.pt:1.1 testResults.pt:1.1

Stephan Richter srichter@cbu.edu
Wed, 10 Jul 2002 20:03:19 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv9815/SQLScript/Views/Browser

Added Files:
	SQLScriptEdit.py SQLScriptTest.py __init__.py configure.zcml 
	edit.pt test.pt testResults.pt 
Log Message:
SQL Scripts that function almost exactely like Zope 2 SQL methods. 


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/SQLScriptEdit.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.
# 
##############################################################################
"""
$Id: SQLScriptEdit.py,v 1.1 2002/07/11 00:03:18 srichter Exp $
"""
from Zope.ComponentArchitecture import getNextService
from Zope.App.Traversing import getParent

from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.OFS.Content.SQLScript.ISQLScript import ISQLScript

class SQLScriptEdit(BrowserView):
    """Edit View for SQL Scripts"""
    __implements__ = BrowserView.__implements__
    __used_for__ = ISQLScript

    def edit(self, connection, arguments, sql):
        if arguments != self.context.getArgumentsString():
            self.context.setArguments(arguments)
        if sql != self.context.getSource():
            self.context.setSource(sql)
        if connection != self.context.getConnectionName():
            self.context.setConnectionName(connection)
        return self.request.response.redirect(self.request['nextURL'])


    def getAllConnections(self):
        parent = getParent(self.context)
        connection_service = getNextService(parent, "ConnectionService")
        connections = connection_service.getAvailableConnections()
        return connections


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/SQLScriptTest.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.
# 
##############################################################################
"""
$Id: SQLScriptTest.py,v 1.1 2002/07/11 00:03:18 srichter Exp $
"""
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.OFS.Content.SQLScript.ISQLScript import ISQLScript
from Zope.App.RDB.DatabaseException import DatabaseException

class SQLScriptTest(BrowserView):
    """Edit View for SQL Scripts"""
    __implements__ = BrowserView.__implements__
    __used_for__ = ISQLScript

    error = None

    def getArguments(self):
        form = self.request.form
        arguments = {}
        for arg in self.context.getArguments().items():
             value = form.get(arg[0])
             if value is None:
                 value = arg[1].get('default')
             if value is not None:
                 arguments[arg[0].encode('UTF-8')] = value
        return arguments
    
    def getTestResults(self):
        try:
            return self.context(**self.getArguments())
        except DatabaseException, error:
            self.error = error
            return []

    def getFormattedError(self):
        error = str(self.error)
        return error

    def getRenderedSQL(self):
        return self.context.getTemplate()(**self.getArguments())


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/__init__.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.
# 
##############################################################################
"""

$Id: __init__.py,v 1.1 2002/07/11 00:03:18 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/configure.zcml ===
<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:browser="http://namespaces.zope.org/browser"
   package="Zope.App.OFS.Content.SQLScript">

<!-- SQL Script View Directives -->

<browser:defaultView
    for=".ISQLScript."
    name="editForm.html" />

<browser:view
    for=".ISQLScript."
    permission="Zope.View"
    factory=".Views.Browser.SQLScriptTest.">
  <browser:page name="testForm.html" template="Views/Browser/test.pt" />
  <browser:page name="testResults.html" 
      template="Views/Browser/testResults.pt" />
</browser:view>

<browser:view
    for=".ISQLScript."
    permission="Zope.View"
    factory=".Views.Browser.SQLScriptEdit.">
  <browser:page name="editForm.html" template="Views/Browser/edit.pt" />
  <browser:page name="edit.html" attribute="edit" />
</browser:view>

<browser:menuItems menu="zmi_views" for=".ISQLScript.">
  <browser:menuItem title="Edit" action="editForm.html"/>
  <browser:menuItem title="Test" action="testForm.html"/>
</browser:menuItems>

<browser:menuItem menu="add_content"
    for="Zope.App.OFS.Container.IAdding."
    title="SQLScript" action="SQLScript" />

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/edit.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Edit SQL Script</title>
</head>
<body>

  <div metal:fill-slot="body">
    <form action="." method="post">
      <input type="hidden" name="nextURL" value=""
          tal:attributes="value request/URL">
    
      <table>      
    	<tbody>       	
    	  <tr>
    	    <th>Connection:</th>
    	    <td>
	      <select size="1" name="connection">
                 <tal:block repeat="name view/getAllConnections">
                   <option value="" selected=""
                     tal:condition="python: name==context.getConnectionName()"
                     tal:attributes="value name" tal:content="name" />
                   <option value=""
                     tal:condition="python: name!=context.getConnectionName()"
                     tal:attributes="value name" tal:content="name" />
                 </tal:block>
	      </select>
            </td>
    	  </tr>
    	  <tr>
    	    <th>Arguments:</th>
    	    <td>
	      <textarea name="arguments" cols="60" rows="5"
                  tal:content="context/getArgumentsString"></textarea> 
            </td>
    	  </tr>
    	  <tr>
    	    <th>SQL Template:</th>
    	    <td>
	      <textarea name="sql" cols="60" rows="10"
                  tal:content="context/getSource"></textarea> 
            </td>
    	  </tr>
    	    	
    	</tbody>     
      </table>
      <input type="submit" name="edit.html:method" value="Save Changes" />
    
    </form> 
  </div>

</body>
</html>

=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/test.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Test SQL Script</title>
</head>
<body>

  <div metal:fill-slot="body">
  <form action="." method="post">

    <pre tal:content="context/getSource" />

    <table border="1"
        tal:define="args context/getArguments" 
        tal:condition="args">
      <tbody>   
        <tr>
	  <th>Argument Name</th>
	  <th>Type</th>
	  <th>Value</th>
        </tr>

        <tr tal:repeat="arg python: args.keys()">
	  <td tal:content="arg"></td>
          <td tal:content="python: args[arg]['type'] or default"> </td>
          <td><input type="text" name="" size="10" value=""
                  tal:attributes="value python: args[arg]['default'] or None;
                                  name arg"/></td>
        </tr>

          	
      </tbody>     
    </table>
  
    <input type="submit" name="testResults.html:method" value="Test" />
    
  </form> 
  </div>

</body>
</html>


=== Added File Zope3/lib/python/Zope/App/OFS/Content/SQLScript/Views/Browser/testResults.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Test SQL Script</title>
</head>
<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/names"
              tal:content="field">Field Name</th>
        </tr>

        <tr tal:repeat="row result">
          <td tal:repeat="field result/names"
              tal:content="python: getattr(row, field)">Value</td>
        </tr>

          	
      </tbody>     
    </table>

    <span tal:condition="view/error">
      <h3>An Error occurred</h3>
      <pre tal:content="view/getFormattedError" />
    </span>

  </div>

</body>
</html>