[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - view.zcml:1.1 views.pt:1.1 configure.zcml:1.51 view.py:1.10 view_search.pt:NONE

Guido van Rossum guido@python.org
Wed, 30 Apr 2003 18:06:32 -0400


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

Modified Files:
	configure.zcml view.py 
Added Files:
	view.zcml views.pt 
Removed Files:
	view_search.pt 
Log Message:
Rough and tumble version of "new UI paradigm" view page
configuration.

XXX This is still missing some features, e.g. the "(change
registration)" link isn't implemented yet, and after adding a view, you
are left in the RegistrationManager rather than at a more useful place
(like maybe the view's edit page or the views service).  Also, it
appears that you can get some weird effects when deleting a view that
has some overlap in specification with another view; I need to look
into that more.



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

<!-- View service -->

  <page
     for = "zope.component.interfaces.IViewService"
     name = "index.html"
     template = "views.pt"
     permission="zope.ManageServices" 
     class="zope.app.browser.services.view.ViewServiceView"
     menu="zmi_views" title="Views"
     />

  <menuItem
      for="zope.app.interfaces.container.IAdding"
      menu="add_service"
      action="zope.app.services.ViewService"
      title="View Service"
      />

<!-- View pages -->

  <editform
    schema="zope.app.interfaces.services.view.IPageConfiguration"
    name="index.html"
    class=".view.PageConfigurationView"
    menu="zmi_views"
    label="Change page"
    permission="zope.ManageServices"
    />

  <addform
      schema="zope.app.interfaces.services.view.IPageConfiguration"
      name="PageConfiguration"
      content_factory=".view.PageConfiguration"
      keyword_arguments="forInterface class_ viewName permission layer"
      set_before_add="template"
      label="Register a view page"
      permission="zope.ManageServices"
      fields="forInterface viewName
              template class_ layer permission status"
      />

<!-- XXX Jim says view configuration doesn't work and aren't well thought out.
     So I'm commenting it out for now.

  <defaultView
    for="zope.app.interfaces.services.view.IViewConfiguration"
    name="edit.html" />

  <editform
    schema="zope.app.interfaces.services.view.IViewConfiguration"
    name="edit.html"
    menu="zmi_views"
    label="Change view"
    permission="zope.ManageServices"
    />

  <addform
      schema="zope.app.interfaces.services.view.IViewConfiguration"
      name="ViewConfiguration"
      content_factory=".view.ViewConfiguration"
      keyword_arguments="forInterface presentationType class_
                           viewName permission"
      set_before_add="layer"
      label="Register a view" 
      permission="zope.ManageServices" 
      fields="forInterface viewName presentationType
              class_ layer permission status"
      />

  <menuItem
      for="zope.app.interfaces.container.IAdding"
      menu="add_configuration"
      action="ViewConfiguration"
      title="View"
      />

-->

</zopeConfigure>


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

<div metal:fill-slot="body"
     tal:define="message view/update; configs view/configInfo"
     >

<h2>Pages registered in this views service:</h2>

      <div class="message" tal:condition="message">
         <span tal:replace="message">view/update message here</span>
         <br><br><i><a href="">(click to clear message)</a></i>
      </div>

<p tal:condition="not:configs">None</p>

<form method="POST" action="index.html" tal:condition="configs">

  <table>
    <tbody>
      <tr tal:repeat="config configs">
        <td>
          <input type="checkbox" name="selected:list"
                 tal:attributes="value config/key" />
          <br>
        </td>
        <td>
          <a tal:condition="config/url" tal:attributes="href config/url">
            <span tal:content="config/viewName" /> for
            <span tal:content="config/forInterface" />
          </a>
          <span tal:condition="not:config/url">
            <span tal:content="config/viewName" /> for
            <span tal:content="config/forInterface" />
          </span>
          <br>
          layer=<span tal:content="config/layer" />,
          type=<span tal:content="config/shortType" />
          <!--
          <a href="." tal:attributes="href config/configurl">
            (change registration)</a>
          -->
        </td>
      </tr>
    </tbody>
  </table>

  <input type="submit" name="Deactivate" value="Deactivate" />
  <input type="submit" name="Delete" value="Delete" />
  <input type="submit" name="Refresh" value="Refresh" />

</form>

<p><a href="../RegistrationManager/@@+/PageConfiguration=">
Add a page to this view service</a></p>

<h3>Search filter:</h3>

<form action="." method="GET">
    <div class="row" tal:content="structure view/forInterface/row" />
    <div class="row" tal:content="structure view/presentationType/row" />
    <div class="row">
    <div class="controls"> 
         <input type="submit" value="Refresh">
         <input type="submit" value="Search" name="SEARCH">
     </div>
    </div>
</form>

</div>

</html>


=== Zope3/src/zope/app/browser/services/configure.zcml 1.50 => 1.51 ===
--- Zope3/src/zope/app/browser/services/configure.zcml:1.50	Wed Apr 30 13:17:12 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Wed Apr 30 18:06:31 2003
@@ -237,91 +237,7 @@
       title="Adapter Service"
       />
 
-<!-- Views -->
-
-<!-- XXX Jim says this doesn't work and isn't well thought out.
-     So commenting this out for now.
-
-  <defaultView
-    for="zope.app.interfaces.services.view.IViewConfiguration"
-    name="edit.html" />
-
-  <editform
-    schema="zope.app.interfaces.services.view.IViewConfiguration"
-    name="edit.html"
-    menu="zmi_views"
-    label="Change view"
-    permission="zope.ManageServices"
-    />
-
-  <addform
-      schema = "zope.app.interfaces.services.view.IViewConfiguration"
-      name= "ViewConfiguration"
-      content_factory = ".view.ViewConfiguration"
-      keyword_arguments = "forInterface presentationType class_
-                           viewName permission"
-      set_before_add = "layer"
-      label = "Register a view" 
-      permission="zope.ManageServices" 
-      fields="forInterface viewName presentationType
-              class_ layer permission status"
-      />
-
-  <menuItem
-      for="zope.app.interfaces.container.IAdding"
-      menu="add_configuration"
-      action="ViewConfiguration"
-      title="View"
-      />
-
--->
-
-  <page
-     for = "zope.component.interfaces.IViewService"
-     name = "index.html"
-     template = "view_search.pt"
-     permission="zope.ManageServices" 
-     class="zope.app.browser.services.view.ViewServiceView"
-     menu="zmi_views" title="Views"
-     />
-
-  <menuItem
-      for="zope.app.interfaces.container.IAdding"
-      menu="add_service"
-      action="zope.app.services.ViewService"
-      title="View Service"
-      />
-
-<!-- View pages -->
-
-  <editform
-    schema="zope.app.interfaces.services.view.IPageConfiguration"
-    name="index.html"
-    class=".view.PageConfigurationView"
-    menu="zmi_views"
-    label="Change page"
-    permission="zope.ManageServices"
-    />
-
-  <addform
-      schema = "zope.app.interfaces.services.view.IPageConfiguration"
-      name= "PageConfiguration"
-      content_factory = ".view.PageConfiguration"
-      keyword_arguments =
-          "forInterface class_ viewName permission layer"
-      set_before_add = "template"
-      label = "Register a view page"
-      permission="zope.ManageServices"
-      fields="forInterface viewName
-              template class_ layer permission status"
-      />
-
-  <menuItem
-      for="zope.app.interfaces.container.IAdding"
-      menu="add_configuration"
-      action="PageConfiguration"
-      title="Page"
-      />
+<!-- Views -->  <include file="view.zcml" />
 
 <!-- ZPT Templates -->
 


=== Zope3/src/zope/app/browser/services/view.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/browser/services/view.py:1.9	Wed Apr 30 13:23:39 2003
+++ Zope3/src/zope/app/browser/services/view.py	Wed Apr 30 18:06:31 2003
@@ -30,12 +30,18 @@
 from zope.interface import Interface
 from zope.schema import TextLine, BytesLine
 from zope.component.interfaces import IPresentation
-from zope.component import getView
+from zope.component import getAdapter, getServiceManager, getView
 from zope.proxy.context import ContextWrapper
 from zope.publisher.browser import BrowserView
 
-from zope.app.form.utility import setUpWidgets
+from zope.app.browser.services.configuration import AddComponentConfiguration
 from zope.app.component.interfacefield import InterfaceField
+from zope.app.form.utility import setUpWidgets
+from zope.app.interfaces.container import IZopeContainer
+from zope.app.interfaces.services.configuration import IUseConfiguration
+from zope.app.interfaces.services.configuration import Unregistered, Registered
+from zope.app.traversing import traverse, getPath, getParent, objectName
+
 # XXX These are not used in this module, but are referenced in configure.zcml.
 #  either configure.zcml should be fixed, or a comment should replace
 #  this one to explain why configure.zcml is importing these two names
@@ -47,7 +53,7 @@
     forInterface = InterfaceField(title=u"For interface",
                                   required=False,
                                   )
-    presentationType = InterfaceField(title=u"Provided interface",
+    presentationType = InterfaceField(title=u"Presentation interface",
                                       required=False,
                                       basetype=IPresentation
                                       )
@@ -63,11 +69,98 @@
 
 class ViewServiceView(BrowserView):
 
+    """Helper class for the default view on the Views service."""
+
     def __init__(self, *args):
         super(ViewServiceView, self).__init__(*args)
         setUpWidgets(self, IViewSearch)
 
+    def update(self):
+        """Possibly deactivate or delete one or more page configurations.
+
+        In that case, issue a message.
+        """
+        todo = self.request.get("selected")
+        doDeactivate = self.request.get("Deactivate")
+        doDelete = self.request.get("Delete")
+        if not todo:
+            if doDeactivate or doDelete:
+                return "Please select at least one checkbox"
+            return None
+        if doDeactivate:
+            return self._deactivate(todo)
+        if doDelete:
+            return self._delete(todo)
+
+    def _getInfosFromKey(self, key):
+        values = key.split(":")
+        assert len(values) == 4, `values`
+        viewName, forInterfaceName, presentationTypeName, layerName = values
+        sm = getServiceManager(self.context)
+        if forInterfaceName == "(Anything)":
+            forInterface = None
+        else:
+            forInterface = sm.resolve(forInterfaceName)
+        presentationType = sm.resolve(presentationTypeName)
+        return self.context.getRegisteredMatching(forInterface,
+                                                  presentationType,
+                                                  viewName,
+                                                  layerName)
+
+    def _deactivate(self, todo):
+        done = []
+        for key in todo:
+            infos = self._getInfosFromKey(key)
+            for info in infos:
+                (forInterface, presentationType,
+                 registry, layer, viewName) = info
+                registry = ContextWrapper(registry, self.context)
+                obj = registry.active()
+                if obj is not None:
+                    obj.status = Registered
+                    done.append(key)
+        if done:
+            return "Deactivated: " + ", ".join(done)
+        else:
+            return "None of the checked utilities were active"
+
+    def _delete(self, todo):
+        errors = []
+        registries = []
+
+        # Check that none of the registrations are active
+        for key in todo:
+            infos = self._getInfosFromKey(key)
+            for info in infos:
+                (forInterface, presentationType,
+                 registry, layer, viewName) = info
+                registry = ContextWrapper(registry, self.context)
+                assert registry
+                if registry.active() is not None:
+                    errors.append(key)
+                    continue
+                registries.append(registry)
+        if errors:
+            return ("Can't delete active page%s: %s; "
+                    "use the Deactivate button to deactivate" %
+                    (len(errors) != 1 and "s" or "", ", ".join(errors)))
+
+        # Now delete the registrations
+        for registry in registries:
+            assert registry
+            assert registry.active() is None # Phase error
+            for info in registry.info():
+                conf = info['configuration']
+                conf.status = Unregistered
+                parent = getParent(conf)
+                name = objectName(conf)
+                container = getAdapter(parent, IZopeContainer)
+                del container[name]
+
+        return "Deleted: %s" % ", ".join([key for key in todo])
+
     def configInfo(self):
+        """Do a search, or (by default) return all view pages."""
         input_for = self.forInterface.getData()
         input_type = self.presentationType.getData()
         input_name = self.viewName.getData()
@@ -79,12 +172,16 @@
 
             forInterface, presentationType, registry, layer, viewName = info
 
+            if not registry:
+                continue
+
             if forInterface is None:
                 forInterface = "(Anything)"
             else:
                 forInterface = (
                     forInterface.__module__ +"."+ forInterface.__name__)
 
+            shortType = presentationType.__name__
             presentationType = (
                 presentationType.__module__ +"."+ presentationType.__name__)
 
@@ -101,17 +198,31 @@
             if input_layer is not None:
                 layer = None
 
-            result.append(
-                {'forInterface': forInterface,
-                 'presentationType': presentationType,
-                 'view': view,
-                 'viewName': viewName,
-                 'layer': layer,
-                 })
+            key = "%s:%s:%s:%s" % (viewName, forInterface,
+                                   presentationType, layer)
+
+            rec = {'forInterface': forInterface,
+                   'presentationType': presentationType,
+                   'shortType': shortType,
+                   'view': view,
+                   'viewName': viewName,
+                   'layer': layer,
+                   'key': key,
+                   'configurl': "@@configureView.html?key=%s" % key,
+                   'url': "",
+                 }
+
+            active = registry.active()
+            if active is not None:
+                rec['url'] = getPath(active)
+
+            result.append(rec)
 
         return result
 
-class PageConfigurationView:
+class PageConfigurationView(BrowserView):
+
+    """Helper class for the page edit form."""
 
     def update(self):
         super(PageConfigurationView, self).update()

=== Removed File Zope3/src/zope/app/browser/services/view_search.pt ===