[Zope3-checkins] CVS: Zope3/src/zope/app/browser - __init__.py:1.1.2.1 absoluteurl.py:1.1.2.1 configure.zcml:1.1.2.1 gadflyda.py:1.1.2.1 introspector.pt:1.1.2.1 introspector.py:1.1.2.1 objectname.py:1.1.2.1 rdb.py:1.1.2.1 rdbadd.pt:1.1.2.1 rdbconnection.pt:1.1.2.1 rdbtestresults.pt:1.1.2.1 rdbtestsql.pt:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:00 -0500


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py absoluteurl.py configure.zcml gadflyda.py 
	introspector.pt introspector.py objectname.py rdb.py rdbadd.pt 
	rdbconnection.pt rdbtestresults.pt rdbtestsql.pt 
Log Message:
Initial renaming before debugging

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


=== Added File Zope3/src/zope/app/browser/absoluteurl.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
# 
##############################################################################
"""

Revision information:
$Id: absoluteurl.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from zope.publisher.browser import BrowserView
from zope.proxy.context.context import getWrapperContainer, getInnerWrapperData
from zope.component import getView

from zope.interface import Interface

class IAbsoluteURL(Interface):

    def __str__():
        """Get a human-readable string representation
        """

    def __repr__():
        """Get a string representation
        """
    
    def __call__():
        """Get a string representation
        """

    def breadcrumbs():
        """Return a tuple like ({'name':name, 'url':url}, ...)

        Name is the name to display for that segment of the breadcrumbs.
        URL is the link for that segment of the breadcrumbs.
        """

class AbsoluteURL(BrowserView):

    def __str__(self):
        context = self.context
        dict = getInnerWrapperData(context)
        name = dict and dict.get('name') or None
        container = getWrapperContainer(context)
        if name is None or container is None:
            raise TypeError, 'Not enough context information to get a URL'
        if name == '.':
            name = dict.get('side_effect_name', name)

        return "%s/%s" % (getView(container, 'absolute_url', self.request),
                          name)

    __call__ = __str__

    def breadcrumbs(self):
        context = self.context
        dict = getInnerWrapperData(context)
        name = dict and dict.get('name') or None
        container = getWrapperContainer(context)
        if name is None or container is None:
            raise TypeError, 'Not enough context information to get a URL'

        if name == '.':
            # The name is meaningless. There is a side-efect name
            # that we need to preserve in the urls (only)
            name = dict.get('side_effect_name', name)
            base = getView(container, 'absolute_url',
                           self.request).breadcrumbs()

            # replace the last step in base with a step with the same
            # name ans an augmented url
            base = base[:-1] + ({
                'name': base[-1]['name'],
                'url': ("%s/%s" % (base[-1]['url'], name)),
                }, )
            return base

        base = getView(container, 'absolute_url', self.request).breadcrumbs()
        base += ({'name': name, 'url': ("%s/%s" % (base[-1]['url'], name))}, )
        return base
        


class SiteAbsoluteURL(BrowserView):

    def __str__(self):
        context = self.context
        dict = getInnerWrapperData(context)
        name = dict and dict.get('name') or None
        if name:
            if name == '.':
                name = dict.get('side_effect_name', name)
            container = getWrapperContainer(context)
            return "%s/%s" % (getView(container, 'absolute_url', self.request),
                              name)
        
        return self.request.getApplicationURL()

    __call__ = __str__

    def breadcrumbs(self):
        context = self.context
        dict = getInnerWrapperData(context)
        name = dict and dict.get('name') or None
        if name:
            # The name is meaningless. There is a side-efect name
            # that we need to preserve in the urls (only)
            if name == '.':
                name = dict.get('side_effect_name', name)
            container = getWrapperContainer(context)
            base = getView(container, 'absolute_url',
                           self.request).breadcrumbs()
            # replace the last step in base with a step with the same
            # name ans an augmented url
            base = base[:-1] + (
                {'name': base[-1]['name'],
                 'url': ("%s/%s" % (base[-1]['url'], name))}, )
            return base

        return ({'name':'', 'url': self.request.getApplicationURL()}, )

        





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

<browser:defaultView
    name="classBrowser.html"
    for = "Interface.Interface"
    permission="Zope.View"
    template="IBrowser.pt"
    factory="zope.app.browser.introspector.IntrospectorView"
    />

<browser:menuItem 
    for = "Interface.Interface" 
    title="Introspector" 
    menu="zmi_views" 
    action="classBrowser.html"/>
 

<browser:defaultView
    name="interfaceBrowser.html"
    for="zope.interface.interfaces.IInterface"
    permission="Zope.View"
    template="IBrowser.pt"
    factory="zope.app.browser.introspector.IntrospectorView"
    /> 

 
</zopeConfigure>

<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:browser='http://namespaces.zope.org/browser'
>

<browser:view
    name="Zope.App.RDB.GadflyDA"
    for="zope.app.interfaces.container.IAdding"
    factory="zope.app.browser.gadflyda.GadflyDAAddView"
    permission="Zope.ManageServices">

  <browser:page name="+" attribute="add" />
  <browser:page name="action.html" attribute="action" />
</browser:view>

<browser:menuItem menu="add_component"
    for="zope.app.interfaces.container.IAdding"
    title="Gadfly DA" 
    action="Zope.App.RDB.GadflyDA"
    description="A Gadfly Database Adapter"/>

</zopeConfigure>

<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.interfaces.rdb.IZopeDatabaseAdapter"
      name="editForm.html" />

  <browser:menuItems menu="zmi_views" for="zope.app.interfaces.rdb.IZopeDatabaseAdapter">
    <browser:menuItem title="Edit" action="editForm.html"/>
    <browser:menuItem title="Test" action="testForm.html"/>
  </browser:menuItems>

  <browser:view
      for="zope.app.interfaces.rdb.IZopeDatabaseAdapter"
      permission="Zope.View"
      factory="zope.app.browser.rdb.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.interfaces.rdb.IZopeDatabaseAdapter"
      permission="Zope.View"
      factory="zope.app.browser.rdb.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/src/zope/app/browser/gadflyda.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.
#
##############################################################################
"""
$Id: gadflyda.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from zope.app.browser.rdb import AdapterAdd
from zope.app.interfaces.container import IAdding


class GadflyDAAddView(AdapterAdd):
    """Provide a user interface for adding a Gadfly DA"""

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



=== Added File Zope3/src/zope/app/browser/introspector.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>

<style metal:fill-slot="style_slot">
.preclass {
    color : #000066;
    font-family : monospace;
    white-space : pre;
    }
th.introspector {
    vertical-align: top;
    }
</style>
</head>

<body>
<div metal:fill-slot="body">
<tal:block 
    tal:define = 
       "global introspector view/getIntrospector;
        global services view/getServicesFor">

<div tal:condition="python:introspector.isInterface()">

<table tal:define = 
    "global interfacedata introspector/getInterfaceDetails">
    <tr>
        <th colspan="2">Interface Browser</th>
    </tr>
    <tr>
        <th class="introspector">Interface :</th>
        <td tal:content="python:interfacedata[0]">Interface</td>
    </tr>
    <tr>
        <th class="introspector">Bases :</th>
        <td>
            <div tal:repeat="interface python:interfacedata[1]">
                <a href="" 
                    tal:attributes="href 
                        string: ++module++${repeat/interface/item}"  
                    tal:content="repeat/interface/item">Interface</a>
            </div>
        </td>
    </tr>
    <tr>
        <th class="introspector">Description :</th>
        <td>
        <!-- the start of all of these preclass spans are carefully 
        spatially placed (in terms of whitespace), because they are 
        "pre" formatted (i.e., whitespace matters within the span) -->
        <span class="preclass"
                tal:content="python:interfacedata[2]">
                Description</span>
        </td>
    </tr>
    <tr>
        <th class="introspector">Attributes :</th>
        <td>
            <div tal:repeat="attributes python:interfacedata[4]">
                <tal:block tal:define="details repeat/attributes/item">
                    <strong tal:content="python:details[0]">
                        Atttribute Name</strong>
                    <div class="preclass">
        <span
                        tal:content="python:details[1]">
                        Attribute Description</span></div>
                </tal:block>
            </div>
        </td>
    </tr>
    <tr>
        <th class="introspector">Methods :</th>
        <td>
            <div tal:repeat="methods python:interfacedata[3]">
                <tal:block tal:define="details repeat/methods/item">
                    <strong tal:content="python:details[0]">
                        Method Name</strong>
                    <strong tal:content="python:details[1]">
                        Signature</strong>
                    <div class="preclass">
        <span 
                        tal:content="python:details[2]">
                        Method Description</span></div>
		</tal:block>
	    </div>
        </td>
    </tr>
    <!-- this section is currently not available
    <tr>
        <th class="introspector">Services :</th>
        <td>
	    <div tal:repeat="servicedic services">
                <span tal:define="dic repeat/servicedic/item">
                    <a tal:content="python:dic.keys()[0]"/>
                </span>
	    </div>
        </td>
    </tr> 
    -->
</table>
</div>

<div tal:condition="python:introspector.isInterface()==0">

<table>
    <tr>
        <th colspan="2">Class Browser</th>
    </tr>
    <tr>
        <th class="introspector">Class :</th>
        <td><span tal:content="introspector/getClass">Name</span></td>
    </tr>
    <tr>
        <th class="introspector">Bases :</th>
        <td>
            <div tal:repeat="base introspector/getBaseClassNames">
                <a href="" 
                    tal:attributes="href 
                        string: ++module++${repeat/base/item}"  
                    tal:content="repeat/base/item">Base</a>
            </div>
        </td>
    </tr>
    <tr>
        <th class="introspector">Module :</th>
        <td><span tal:content="introspector/getModule">Module</span></td>
    </tr>
    <tr>
        <th>Description :</th>
        <td>
        <span class="preclass" 
                tal:content="introspector/getDocString">
                Description</span>
        </td>
    </tr>
    <tr>
        <th class="introspector">Interface :</th>
        <td>
            <div tal:repeat="interface introspector/getInterfaceNames">
                <a href="" 
                    tal:attributes="href 
                        string: ++module++${repeat/interface/item}"
                    tal:content="repeat/interface/item">Interface</a>
            </div>
        </td>
    </tr>
</table>
</div>

</tal:block>

</div>
</body>
</html>



=== Added File Zope3/src/zope/app/browser/introspector.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.
# 
##############################################################################
from zope.component import getAdapter
from zope.publisher.browser import BrowserView
from zope.app.interfaces.introspector import IIntrospector
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.component import getServiceManager, getAdapter, \
     queryServiceManager, getServiceDefinitions, queryAdapter, getService
# from Zope.App.OFS.Services.IConfigureFor import IConfigureFor
from zope.component.exceptions import ComponentLookupError

class IntrospectorView(BrowserView):
    
    def getIntrospector(self):
        introspector = getAdapter(self.context, IIntrospector)
        introspector.setRequest(self.request)
        return introspector

    def getServicesFor(self):
        services = []
        #sm = getServiceManager(self.context)
        #for stype, interface in sm.getServiceDefinitions():
        #    try:
        #        service = getService(self.context, stype)
        #    except ComponentLookupError:
        #        pass
        #    else:
        #        adapter = queryAdapter(service, IConfigureFor)
        #        if adapter is not None and adapter.hasConfigurationFor(self.context):
        #            search_result = service.getRegisteredMatching(self.context, None, [], self.context)
        #            directive_path = []
        #            if search_result:
        #                for eachitem in search_result:
        #                    dir_list = eachitem['directives']
        #                    component_path = eachitem['component_path']
        #                    for item in dir_list:
        #                        directives = item[2]                         
        #                        if directives:
        #                            if directives[0] is None:
        #                                directives = directives[1:]
        #                            for directive in directives:
        #                                for component in component_path:
        #                                    if component['component'] == directive:
        #                                        directive_path.append(component['path'])
        #            services.append({
        #                'type': stype,
        #                'service': service,
        #                'path': directive_path
        #                })
        return services


=== Added File Zope3/src/zope/app/browser/objectname.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
# 
##############################################################################
"""

Revision information:
$Id: objectname.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from zope.publisher.interfaces.browser import IBrowserView
from zope.proxy.context.context import getInnerWrapperData
from zope.app.traversing.objectname \
    import IObjectName, ObjectName, SiteObjectName

from zope.interface import Interface

class ObjectNameView(ObjectName):

    __implements__ = IBrowserView, IObjectName
    
    def __init__(self, context, request):
        self.context = context


class SiteObjectNameView(SiteObjectName):

    __implements__ = IBrowserView, IObjectName
    
    def __init__(self, context, request):
        pass


=== Added File Zope3/src/zope/app/browser/rdb.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: rdb.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from zope.proxy.introspection import removeAllProxies
from zope.publisher.browser import BrowserView
from zope.app.interfaces.rdb import IZopeDatabaseAdapter
from zope.app.rdb 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


"""Zope database adapter edit view

$Id: rdb.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from zope.publisher.browser import BrowserView
from zope.app.interfaces.rdb 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])


"""Zope database adapter adding view

$Id: rdb.py,v 1.1.2.1 2002/12/23 19:30:58 jim Exp $
"""
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.component import getFactory

from zope.publisher.browser import BrowserView
from zope.app.interfaces.container 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/src/zope/app/browser/rdbadd.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/src/zope/app/browser/rdbconnection.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/src/zope/app/browser/rdbtestresults.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/src/zope/app/browser/rdbtestsql.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>