[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/RDB/Browser - AdapterAdd.py:1.1.2.1 Connection.py:1.1.2.1 TestSQL.py:1.1.2.1 __init__.py:1.1.2.1 add.pt:1.1.2.1 configure.zcml:1.1.2.1 connection.pt:1.1.2.1 testResults.pt:1.1.2.1 testSQL.pt:1.1.2.1

Marius Gedminas mgedmin@codeworks.lt
Wed, 11 Dec 2002 07:37:41 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB/Browser
In directory cvs.zope.org:/tmp/cvs-serv816/lib/python/Zope/App/RDB/Browser

Added Files:
      Tag: named-component-configuration-branch
	AdapterAdd.py Connection.py TestSQL.py __init__.py add.pt 
	configure.zcml connection.pt testResults.pt testSQL.pt 
Log Message:
Moved IZopeDatabaseAdapter views into Zope.App.RDB

=== Added File Zope3/lib/python/Zope/App/RDB/Browser/AdapterAdd.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Zope database adapter adding view

$Id: AdapterAdd.py,v 1.1.2.1 2002/12/11 12:37:40 mgedmin Exp $
"""
from Zope.App.PageTemplate import ViewPageTemplateFile
from Zope.ComponentArchitecture import getFactory

from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.OFS.Container.IAdding import IAdding


class AdapterAdd(BrowserView):
    """A base class for Zope database adapter adding views.

    Subclasses need to override _adapter_factory_id.
    """

    __used_for__ = IAdding

    # This needs to be overridden by the actual implementation
    _adapter_factory_id = None

    add = ViewPageTemplateFile('add.pt')

    def action(self, dsn):
        factory = getFactory(self, self._adapter_factory_id)
        adapter = factory(dsn)
        self.context.add(adapter)
        self.request.response.redirect(self.context.nextURL())


=== Added File Zope3/lib/python/Zope/App/RDB/Browser/Connection.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.
#
##############################################################################
"""Zope database adapter edit view

$Id: Connection.py,v 1.1.2.1 2002/12/11 12:37:40 mgedmin Exp $
"""
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.RDB.IZopeDatabaseAdapter import IZopeDatabaseAdapter

class Connection(BrowserView):

    __used_for__ = IZopeDatabaseAdapter

    def edit(self, dsn):
        self.context.setDSN(dsn)
        return self.request.response.redirect(self.request.URL[-1])

    def connect(self):
        self.context.connect()
        return self.request.response.redirect(self.request.URL[-1])

    def disconnect(self):
        self.context.disconnect()
        return self.request.response.redirect(self.request.URL[-1])


=== Added File Zope3/lib/python/Zope/App/RDB/Browser/TestSQL.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.
#
##############################################################################
"""Zope database adapter test view

$Id: TestSQL.py,v 1.1.2.1 2002/12/11 12:37:40 mgedmin Exp $
"""
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.RDB.IZopeDatabaseAdapter import IZopeDatabaseAdapter
from Zope.App.RDB.Util import queryForResults


class TestSQL(BrowserView):

    __used_for__ = IZopeDatabaseAdapter

    def getTestResults(self):
        sql = self.request.form['sql']
        adapter = removeAllProxies(self.context)
        result = queryForResults(adapter(), sql)
        return result


=== Added File Zope3/lib/python/Zope/App/RDB/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.
#
##############################################################################
"""Common views for Zope database adapters

$Id: __init__.py,v 1.1.2.1 2002/12/11 12:37:40 mgedmin Exp $
"""


=== Added File Zope3/lib/python/Zope/App/RDB/Browser/add.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Add Relational Database Adapter</title>
</head>
<body>

  <div metal:fill-slot="body">

    <form action="action.html" method="post" enctype="multipart/form-data">

      <table>
        <tbody>

          <tr>
            <th>Connection URI:</th>
            <td>
              Template:
              dbi://username:password@host:port/dbname;param1=value...<br />
              <input type="text" name="dsn" size="40" value="dbi://dbname">
            </td>
          </tr>

        </tbody>
      </table>

      <input type="submit" name="add" value="Add" />

    </form>

  </div>

</body>
</html>


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

<!-- ZopeDatabaseAdapter default views -->

  <browser:defaultView for="Zope.App.RDB.IZopeDatabaseAdapter."
      name="editForm.html" />

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

  <browser:view
      for="Zope.App.RDB.IZopeDatabaseAdapter."
      permission="Zope.View"
      factory=".Browser.Connection.">
    <browser:page name="editForm.html"
        template="Browser/connection.pt" />
    <browser:page name="edit.html" attribute="edit" />
    <browser:page name="connect.html" attribute="connect" />
    <browser:page name="disconnect.html" attribute="disconnect" />
  </browser:view>

  <browser:view
      for="Zope.App.RDB.IZopeDatabaseAdapter."
      permission="Zope.View"
      factory=".Browser.TestSQL.">
    <browser:page name="testForm.html" template="Browser/testSQL.pt" />
    <browser:page name="test.html" template="Browser/testResults.pt" />
  </browser:view>

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/RDB/Browser/connection.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Add Relational Database Adapter</title>
</head>
<body>

  <div metal:fill-slot="body">

    <form action="." method="post" enctype="multipart/form-data">
    
      <table>      
    	<tbody>   
    	
    	  <tr>
    	    <th>Connection URI:</th>
    	    <td>
              Template: 
              dbi://username:password@host:port/dbname;param1=value...<br />
	      <input type="text" name="dsn" size="40" value=""
                  tal:attributes="value context/getDSN">  
            </td>
    	  </tr>
    	    	
    	</tbody>     
      </table>
    
      <input type="submit" name="edit.html:method" value="Save Changes" />
      <input type="submit" name="connect.html:method" value="Connect"
          tal:condition="python: not context.isConnected()" />
      <input type="submit" name="disconnect.html:method" value="Disconnect"
          tal:condition="python: context.isConnected()" />
    
    </form> 

  </div>

</body>
</html>

=== Added File Zope3/lib/python/Zope/App/RDB/Browser/testResults.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Database Adapter - Test Connection</title>
</head>
<body>

  <div metal:fill-slot="body">

    <pre tal:content="request/form/sql" />

    <table border="1"
        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>

  </div>

</body>
</html>


=== Added File Zope3/lib/python/Zope/App/RDB/Browser/testSQL.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
  <title>Database Adapter - Test Connection</title>
</head>
<body>

  <div metal:fill-slot="body">

    <form action="." method="post" enctype="multipart/form-data">

      <p>Here you can enter an SQL statement, so you can test the
      connection.</p>

      <table>
        <tbody>

          <tr>
            <th>Query</th>
            <td>
              <textarea name="sql" cols="60" rows="10"
                >SELECT * FROM Table</textarea>
            </td>
          </tr>

        </tbody>
      </table>

      <input type="submit" name="test.html:method" value="Execute" />

    </form>

  </div>

</body>
</html>