[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser - PageConfigSummary.pt:1.1.2.1 ViewConfigSummary.pt:1.1.2.1 add_view_config.pt:1.1.2.1 field.py:1.1.2.1 view.py:1.1.2.1 view_search.pt:1.1.2.1 zpt.py:1.1.2.1 adapter_search.pt:1.1.2.2 configure.zcml:1.3.4.2

Jim Fulton jim@zope.com
Thu, 12 Dec 2002 10:20:26 -0500


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

Modified Files:
      Tag: AdapterAndView-branch
	adapter_search.pt configure.zcml 
Added Files:
      Tag: AdapterAndView-branch
	PageConfigSummary.pt ViewConfigSummary.pt add_view_config.pt 
	field.py view.py view_search.pt zpt.py 
Log Message:
Got view service and view registration working TTW (sort of).

This includes a new "View Package". You set up a view package with
default registration parameters. Then, as you add ZPT templates to the
package, they are automatically registered as views.

There are lots of rough edges that need to be smoothed out after the
sprint and before this branch merge.



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


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


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/add_view_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>


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/field.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.
# 
##############################################################################
"""A widget for ComponentLocation field.

$Id: field.py,v 1.1.2.1 2002/12/12 15:19:54 jim Exp $
"""
__metaclass__ = type

from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
from Zope.ComponentArchitecture import getServiceManager

class ComponentLocationWidget(BrowserWidget):

    def _convert(self, value):
        return value or None

    def __call__(self):
        selected = self._showData()
        service_manager = getServiceManager(self.context.context)
        info = service_manager.queryComponent(self.context.type)
        result = []

        result.append('<select name="%s">' % self.name)
        result.append('<option></option>')

        for item in info:
            item = item['path']
            if item == selected:
                result.append('<option selected>%s</option>' % item)
            else:
                result.append('<option>%s</option>' % item)

        result.append('</select>')

        return "\n".join(result)


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/view.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 view configuration.

  ViewSeviceView -- 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

  ViewConfigrationAdd

$Id: view.py,v 1.1.2.1 2002/12/12 15:19:54 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 IViewConfiguration, IViewConfigurationInfo
from Zope.App.OFS.Services.interfaces \
     import IPageConfiguration, IPageConfigurationInfo
from Zope.Event import publish
from Zope.Event.ObjectEvent import ObjectCreatedEvent
from Zope.App.OFS.Services.ConfigurationInterfaces import IConfiguration
from Zope.App.OFS.Services.view import ViewConfiguration, PageConfiguration
from Zope.App.ComponentArchitecture.InterfaceField import InterfaceField
from Interface import Interface
from Zope.ComponentArchitecture import getView
from Zope.Proxy.ContextWrapper import ContextWrapper
from Zope.Schema import TextLine, BytesLine
from Zope.ComponentArchitecture.IPresentation import IPresentation

class IViewSearch(Interface):

    forInterface = InterfaceField(title=u"For interface",
                                  required=False,
                                  )
    presentationType = InterfaceField(title=u"Provided interface",
                                      required=False,
                                      type=IPresentation
                                      )

    viewName = TextLine(title=u'View name',
                        required=False,
                        )

    layer = BytesLine(title=u'Layer',
                      required=False,
                        )
    

class ViewServiceView(BrowserView):

    def __init__(self, *args):
        super(ViewServiceView, self).__init__(*args)
        setUpWidgets(self, IViewSearch)
    
    def configInfo(self):
        input_for = self.forInterface.getData()
        input_type = self.presentationType.getData()
        input_name = self.viewName.getData()
        input_layer = self.layer.getData()

        result = []
        for info in self.context.getRegisteredMatching(
            input_for, input_type, input_name, input_layer):

            forInterface, presentationType, registry, layer, viewName = info
            
            forInterface = (
                forInterface.__module__ +"."+ forInterface.__name__)
            presentationType = (
                presentationType.__module__ +"."+ presentationType.__name__)

            registry = ContextWrapper(registry, self.context)
            view = getView(registry, "ChangeConfigurations", self.request)
            prefix = md5.new('%s %s' %
                             (forInterface, presentationType)).hexdigest()
            view.setPrefix(prefix)
            view.update()

            if input_name is not None:
                viewName = None

            if input_layer is not None:
                layer = None
            
            result.append(
                {'forInterface': forInterface,
                 'presentationType': presentationType,
                 'view': view,
                 'viewName': viewName,
                 'layer': layer,
                 })

        return result


class ViewConfigurationAdd(BrowserView):

    def __init__(self, *args):
        super(ViewConfigurationAdd, self).__init__(*args)
        setUpWidgets(self, IViewConfiguration)

    def refresh(self):
        if "FINISH" in self.request:
            data = getWidgetsData(self, IViewConfigurationInfo)
            configuration = ViewConfiguration(**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(IViewConfigurationInfo)]
                +
                [getattr(self, name)
                 for name in fieldNames(IConfiguration)]
                )

class PageConfigurationAdd(BrowserView):

    def __init__(self, *args):
        super(PageConfigurationAdd, self).__init__(*args)
        setUpWidgets(self, IPageConfiguration)

    def refresh(self):
        if "FINISH" in self.request:
            data = getWidgetsData(self, IPageConfigurationInfo)
            configuration = PageConfiguration(**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(IPageConfigurationInfo)]
                +
                [getattr(self, name)
                 for name in fieldNames(IConfiguration)]
                )


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/view_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/presentationType/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      
      tal:define="layer not:request/field.layer|nothing;
                  viewName not:request/field.viewName|nothing;
                  "
      >
    <tr>
       <th>For/<br>Provided</th>
       <th tal:condition="layer">Layer</th>
       <th tal:condition="viewName">View name</th>
       <th>Configuration</th>
       
    </tr>
    
    <tr tal:repeat="config view/configInfo">
      <td> <span tal:content="config/forInterface" />/<br>
           <span tal:content="config/presentationType" />
      </td>
      <td tal:condition="layer"
          tal:content="config/layer">Layer</td>
      <td tal:condition="viewName"
          tal:content="config/viewName">View name</td>      
      <td tal:content="structure config/view" />
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td> 
         <input type="submit" value="Update" name="UPDATE_SUBMIT">
      </td>
    </tr>
  </table>
</form>

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


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/zpt.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.
# 
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: zpt.py,v 1.1.2.1 2002/12/12 15:19:54 jim Exp $
"""
from Zope.Publisher.Browser.BrowserView import BrowserView

__metaclass__ = type

class Source(BrowserView):

    def __call__(self):
        self.request.response.setHeader('content-type',
                                        self.context.contentType)
        return self.context.source

    


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/adapter_search.pt 1.1.2.1 => 1.1.2.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/Browser/adapter_search.pt:1.1.2.1	Wed Dec 11 06:41:09 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/adapter_search.pt	Thu Dec 12 10:19:54 2002
@@ -42,6 +42,7 @@
          <input type="submit" value="Update" name="UPDATE_SUBMIT">
       </td>
     </tr>
+  </table>
 </form>
 
 </div></body></html>


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml 1.3.4.1 => 1.3.4.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml:1.3.4.1	Wed Dec 11 06:41:09 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml	Thu Dec 12 10:19:54 2002
@@ -5,6 +5,8 @@
    package="Zope.App.OFS.Services"
    >
 
+<!-- Configuration status widget -->
+
 <view
     for=".ConfigurationInterfaces.IConfigurationStatus"
     name="edit"
@@ -13,6 +15,18 @@
     permission="Zope.ManageServices"
     />
 
+<!-- Component Location widget -->
+
+<view
+    for=".field.IComponentLocation"
+    name="edit"
+    factory=".Browser.field.ComponentLocationWidget"
+    allowed_interface="Zope.App.Forms.Views.Browser.IBrowserWidget."
+    permission="Zope.ManageServices"
+    />
+
+<!-- Configuration Registry -->
+
 <view
     for=".ConfigurationInterfaces.IConfigurationRegistry"
     name="ChangeConfigurations"
@@ -24,6 +38,8 @@
 
 <defaultView for=".interfaces.IAdapterConfiguration" name="edit.html" />
 
+<!-- Adapters -->
+
 <form:edit
     schema=".interfaces.IAdapterConfiguration"
     name="edit.html"
@@ -82,7 +98,151 @@
       for="Zope.App.OFS.Container.IAdding."
       menu="add_component"
       action="Zope.App.OFS.Services.AdapterService"
-      title="Adapter"
+      title="Adapter Service"
+      />
+
+<!-- Views -->
+
+<form:edit
+    schema=".interfaces.IViewConfiguration"
+    name="edit.html"
+    label="Change view"
+    permission="Zope.ManageServices"
+    />
+
+<form:subedit
+    schema=".interfaces.IViewConfiguration"
+    name="ItemEdit"
+    label="View"
+    permission="Zope.ManageServices"
+    fields="forInterface viewName presentationType factoryName layer
+            title status"
+    />
+
+<view
+     for = ".interfaces.IViewConfiguration"
+     name = "ConfigurationSummary"
+     template = "Browser/ViewConfigSummary.pt"
+     permission="Zope.ManageServices" 
+     />  
+
+<view
+     for = "Zope.App.OFS.Container.IAdding."
+     name="ViewConfiguration"
+     permission="Zope.ManageServices" 
+     factory=".Browser.view.ViewConfigurationAdd"
+     >
+  <page
+      name="index.html"
+      template="Browser/add_adapter_config.pt"
+      />
+</view>
+
+<menuItem
+      for="Zope.App.OFS.Container.IAdding."
+      menu="add_configuration"
+      action="ViewConfiguration"
+      title="View"
+      />
+
+<defaultView
+     for = "Zope.ComponentArchitecture.IViewService."
+     name = "index.html"
+     />
+
+<view
+     for = "Zope.ComponentArchitecture.IViewService."
+     name = "index.html"
+     template = "Browser/view_search.pt"
+     permission="Zope.ManageServices" 
+     class=".Browser.view.ViewServiceView"
+     />  
+
+<menuItem
+      for="Zope.App.OFS.Container.IAdding."
+      menu="add_component"
+      action="Zope.App.OFS.Services.ViewService"
+      title="View Service"
       />
+
+<!-- View pages -->
+
+
+<form:edit
+    schema=".interfaces.IPageConfiguration"
+    name="edit.html"
+    label="Change page"
+    permission="Zope.ManageServices"
+    />
+
+<form:subedit
+    schema=".interfaces.IPageConfiguration"
+    name="ItemEdit"
+    label="Page"
+    permission="Zope.ManageServices"
+    fields="forInterface viewName presentationType factoryName layer 
+            title status"
+    />
+
+<view
+     for = ".interfaces.IPageConfiguration"
+     name = "ConfigurationSummary"
+     template = "Browser/PageConfigSummary.pt"
+     permission="Zope.ManageServices" 
+     />  
+
+<view
+     for = "Zope.App.OFS.Container.IAdding."
+     name="PageConfiguration"
+     permission="Zope.ManageServices" 
+     factory=".Browser.view.PageConfigurationAdd"
+     >
+  <page
+      name="index.html"
+      template="Browser/add_adapter_config.pt"
+      />
+</view>
+
+<menuItem
+      for="Zope.App.OFS.Container.IAdding."
+      menu="add_configuration"
+      action="PageConfiguration"
+      title="Page"
+      />
+
+<!-- ZPT Templates -->
+
+<defaultView
+    for=".interfaces.IZPTTemplate"
+    name="index.html"
+    />
+
+<view 
+    for=".interfaces.IZPTTemplate"
+    name="index.html"
+    factory=".Browser.zpt.Source"
+    permission="Zope.ManageServices"
+    />
+
+<form:edit
+    schema=".interfaces.IZPTTemplate"
+    name="edit.html"
+    label="ZPT Template"
+    permission="Zope.ManageServices"
+    />
+
+<menuItems menu="zmi_views" for=".interfaces.IZPTTemplate">
+  <menuItem action="edit.html" title="Edit" />
+  <menuItem title="View" action="index.html"/>
+</menuItems>
+
+<menuItem
+    for="Zope.App.OFS.Container.IAdding."
+    menu="add_component"
+    action="Zope.app.services.zpt.template"
+    title="ZPT Template"
+    />
+
+
 
 </zope:zopeConfigure>