[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser - AdapterConfigSummary.pt:1.1.2.1 adapter.py:1.1.2.1 adapter_search.pt:1.1.2.1 add_adapter_config.pt:1.1.2.1 configure.zcml:1.3.4.1

Jim Fulton jim@zope.com
Wed, 11 Dec 2002 06:41:10 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/Browser
In directory cvs.zope.org:/tmp/cvs-serv23318/lib/python/Zope/App/OFS/Services/Browser

Modified Files:
      Tag: AdapterAndView-branch
	configure.zcml 
Added Files:
      Tag: AdapterAndView-branch
	AdapterConfigSummary.pt adapter.py adapter_search.pt 
	add_adapter_config.pt 
Log Message:
Got AdapterService views working.

=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/AdapterConfigSummary.pt ===
<span tal:replace="context/factoryName" />


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/adapter.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.
# 
##############################################################################
"""Views for local adapter configuration.

  AdapterSeviceView -- it's a bit different from other services, as it
  has a lot of things in it, so we provide a search interface:

    search page
    browsing page

  AdapterConfigrationAdd

$Id: adapter.py,v 1.1.2.1 2002/12/11 11:41:09 jim Exp $
"""
__metaclass__ = type

import md5
from Zope.App.Forms.Utility \
     import setUpWidgets, getWidgetsData, getWidgetsDataForContent, fieldNames
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.OFS.Services.interfaces \
     import IAdapterConfiguration, IAdapterConfigurationInfo
from Zope.Event import publish
from Zope.Event.ObjectEvent import ObjectCreatedEvent
from Zope.App.OFS.Services.ConfigurationInterfaces import IConfiguration
from Zope.App.OFS.Services.adapter import AdapterConfiguration
from Zope.App.ComponentArchitecture.InterfaceField import InterfaceField
from Interface import Interface
from Zope.ComponentArchitecture import getView
from Zope.Proxy.ContextWrapper import ContextWrapper
class IAdapterSearch(Interface):

    forInterface = InterfaceField(title=u"For interface",
                                  required=False,
                                  )
    providedInterface = InterfaceField(title=u"Provided interface",
                                       required=False,
                                       )
    

class AdapterServiceView(BrowserView):

    def __init__(self, *args):
        super(AdapterServiceView, self).__init__(*args)
        setUpWidgets(self, IAdapterSearch)
    
    def configInfo(self):
        forInterface = self.forInterface.getData()
        providedInterface = self.providedInterface.getData()


        result = []
        for (forInterface, providedInterface, registry
             ) in self.context.getRegisteredMatching(forInterface,
                                                     providedInterface):
            forInterface = (
                forInterface.__module__ +"."+ forInterface.__name__)
            providedInterface = (
                providedInterface.__module__ +"."+ providedInterface.__name__)

            registry = ContextWrapper(registry, self.context)
            view = getView(registry, "ChangeConfigurations", self.request)
            prefix = md5.new('%s %s' %
                             (forInterface, providedInterface)).hexdigest()
            view.setPrefix(prefix)
            view.update()
            result.append(
                {'forInterface': forInterface,
                 'providedInterface': providedInterface,
                 'view': view,
                 })

        return result


class AdapterConfigurationAdd(BrowserView):

    def __init__(self, *args):
        super(AdapterConfigurationAdd, self).__init__(*args)
        setUpWidgets(self, IAdapterConfiguration)

    def refresh(self):
        if "FINISH" in self.request:
            data = getWidgetsData(self, IAdapterConfigurationInfo)
            configuration = AdapterConfiguration(**data)
            publish(self.context.context, ObjectCreatedEvent(configuration))
            configuration = self.context.add(configuration)
            getWidgetsDataForContent(self, IConfiguration, configuration)
            self.request.response.redirect(self.context.nextURL())
            return False

        return True

    def getWidgets(self):
        return ([getattr(self, name)
                 for name in fieldNames(IAdapterConfigurationInfo)]
                +
                [getattr(self, name)
                 for name in fieldNames(IConfiguration)]
                )


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/adapter_search.pt ===
<html metal:use-macro="views/standard_macros/page">
<head><title></title></head>
<body>
<div metal:fill-slot="body">

<form action="." method="post"
      tal:attributes="action request/URL"
      >
  <table>
    <tr tal:content="structure view/forInterface/row" />
    <tr tal:content="structure view/providedInterface/row" />
    <tr>
      <td></td>
      <td> 
         <input type="submit" value="Refresh">
         <input type="submit" value="Search" name="SEARCH">
     </td>
    </tr>
  </table>
</form>

<form action="." method="post"
      tal:attributes="action request/URL"
      tal:condition="request/SEARCH|nothing"
      >
  <table>
    <tr>
       <th>For/<br>Provided</th>
       <th>Configuration</th>
    </tr>
    
    <tr tal:repeat="config view/configInfo">
      <td> <span tal:content="config/forInterface" />/<br>
           <span tal:content="config/providedInterface" />
      </td>
      <td tal:content="structure config/view" />
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td> 
         <input type="submit" value="Update" name="UPDATE_SUBMIT">
      </td>
    </tr>
</form>

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


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/add_adapter_config.pt ===
<html metal:use-macro="views/standard_macros/page">
<head><title></title></head>
<body>
<div metal:fill-slot="body">

<form action="." method="post"
      tal:attributes="action request/URL"
      tal:condition="view/refresh"
      >
  <table>
     <tr tal:repeat="widget view/getWidgets"
         tal:content="structure widget/row">
       <td>Label</td>
       <td>Roles</td>
     </tr>
  </table>
  <input type="submit" value="Refresh" />
  <input type="submit" name="FINISH" value="Finish" />
</form>

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


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml 1.3 => 1.3.4.1 ===
--- Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml:1.3	Mon Dec  9 11:09:19 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml	Wed Dec 11 06:41:09 2002
@@ -1,6 +1,7 @@
 <zope:zopeConfigure
    xmlns:zope='http://namespaces.zope.org/zope'
    xmlns="http://namespaces.zope.org/browser"
+   xmlns:form="http://namespaces.zope.org/form"
    package="Zope.App.OFS.Services"
    >
 
@@ -20,5 +21,68 @@
     allowed_interface="Zope.App.Forms.Browser.IFormCollaborationView."
     permission="Zope.ManageServices"
     />
+
+<defaultView for=".interfaces.IAdapterConfiguration" name="edit.html" />
+
+<form:edit
+    schema=".interfaces.IAdapterConfiguration"
+    name="edit.html"
+    label="Change adapter"
+    permission="Zope.ManageServices"
+    />
+
+<form:subedit
+    schema=".interfaces.IAdapterConfiguration"
+    name="ItemEdit"
+    label="Adapter"
+    permission="Zope.ManageServices"
+    fields="forInterface providedInterface factoryName title status"
+    />
+
+<view
+     for = ".interfaces.IAdapterConfiguration"
+     name = "ConfigurationSummary"
+     template = "Browser/AdapterConfigSummary.pt"
+     permission="Zope.ManageServices" 
+     />  
+
+<defaultView
+     for = "Zope.ComponentArchitecture.IAdapterService."
+     name = "index.html"
+     />
+
+<view
+     for = "Zope.ComponentArchitecture.IAdapterService."
+     name = "index.html"
+     template = "Browser/adapter_search.pt"
+     permission="Zope.ManageServices" 
+     class=".Browser.adapter.AdapterServiceView"
+     />  
+
+<view
+     for = "Zope.App.OFS.Container.IAdding."
+     name="AdapterConfiguration"
+     permission="Zope.ManageServices" 
+     factory=".Browser.adapter.AdapterConfigurationAdd"
+     >
+  <page
+      name="index.html"
+      template="Browser/add_adapter_config.pt"
+      />
+</view>
+
+<menuItem
+      for="Zope.App.OFS.Container.IAdding."
+      menu="add_configuration"
+      action="AdapterConfiguration"
+      title="Adapter"
+      />
+
+<menuItem
+      for="Zope.App.OFS.Container.IAdding."
+      menu="add_component"
+      action="Zope.App.OFS.Services.AdapterService"
+      title="Adapter"
+      />
 
 </zope:zopeConfigure>