[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - cache.py:1.13 cache.zcml:1.8 caches.pt:1.13 configure.zcml:1.71 connection.py:1.17 connection.zcml:1.12 service.py:1.38 configureCache.pt:NONE

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 14:34:42 EDT 2003


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

Modified Files:
	cache.py cache.zcml caches.pt configure.zcml connection.py 
	connection.zcml service.py 
Removed Files:
	configureCache.pt 
Log Message:
Just to make it worth the effort, here is the rewrite of the Caching Service
to use local utilities. I am amazed how much cruft can go away. There are
still some dead chickens left that can be easily fixed by providing a 
default overview screen for these services and remodeling the local utility
service a bit.

Jim,

noone has complained about the changes yet. Are you guys at ZC having a fit
with it? I think in general people just not use these components heavily
yet and it is no big deal to create them, since their data does not contain
much programming logic (i.e. they are easily recreated) and there are only
a few around ata time usually.


=== Zope3/src/zope/app/browser/services/cache.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/browser/services/cache.py:1.12	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/cache.py	Tue Aug 19 13:34:02 2003
@@ -15,155 +15,51 @@
 
 $Id$
 """
-from zope.app.browser.services.registration import AddComponentRegistration
+from zope.app import zapi
+from zope.app.browser.services.service import ComponentAdding
+from zope.app.component.nextservice import queryNextService
 from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.interfaces.container import IZopeContainer
-from zope.app.interfaces.services.registration import IRegistered
-from zope.app.interfaces.services.registration import ActiveStatus
-from zope.app.interfaces.services.registration import RegisteredStatus
-from zope.app.interfaces.services.registration import UnregisteredStatus
-from zope.app.traversing import traverse, getPath, getParent, getName
-from zope.component import getAdapter, getView
+from zope.app.interfaces.cache import ICache
+from zope.app.services.servicenames import Caching, Utilities
 
 class Caches:
-    # self.context is the local caching service
+    """View for local caching services."""
 
-    def update(self):
-        """Possibly delete one or more caches.
+    def getLocalCaches(self):
+        caches = []
+        utilities = zapi.getService(self.context, Utilities)
+        matching = utilities.getRegisteredMatching(ICache)
+        for match in matching:
+            caches.append(self.buildInfo(match))
+        return caches
 
-        In that case, issue a message.
-        """
-        todo = self.request.get("selected")
-        doActivate = self.request.get("Activate")
-        doDeactivate = self.request.get("Deactivate")
-        doDelete = self.request.get("Delete")
-        if not todo:
-            if doActivate or doDeactivate or doDelete:
-                return _("Please select at least one checkbox")
-            return None
-        if doActivate:
-            return self._activate(todo)
-        if doDeactivate:
-            return self._deactivate(todo)
-        if doDelete:
-            return self._delete(todo)
-
-    def _activate(self, todo):
-        done = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            obj = registry.active()
-            if obj is None:
-                # Activate the first registered registration
-                obj = registry.info()[0]['registration']
-                obj.status = ActiveStatus
-                done.append(name)
-        if done:
-            s = _("Activated: ${activated_caches}")
-            s.mapping = {'activated_caches': ", ".join(done)}
-            return s
-        else:
-            return _("All of the checked caches were already active")
-
-    def _deactivate(self, todo):
-        done = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            obj = registry.active()
-            if obj is not None:
-                obj.status = RegisteredStatus
-                done.append(name)
-        if done:
-            s = _("Deactivated: ${deactivated_caches}")
-            s.mapping = {'deactivated_caches': ", ".join(done)}
-            return s
-        else:
-            return _("None of the checked caches were active")
-
-    def _delete(self, todo):
-        errors = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            assert registry
-            if registry.active() is not None:
-                errors.append(name)
-                continue
-        if errors:
-            s = _("Can't delete active cache(s): ${cache_names}; "
-                  "use the Deactivate button to deactivate")
-            s.mapping = {'cache_names': ", ".join(errors)}
-            return s
-
-        # 1) Delete the registrations
-        caches = {}
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            assert registry
-            assert registry.active() is None # Phase error
-            for info in registry.info():
-                conf = info['registration']
-                obj = conf.getComponent()
-                path = getPath(obj)
-                caches[path] = obj
-                conf.status = UnregisteredStatus
-                parent = getParent(conf)
-                name = getName(conf)
-                container = getAdapter(parent, IZopeContainer)
-                del container[name]
-
-        # 2) Delete the cache objects
-        for path, obj in caches.items():
-            parent = getParent(obj)
-            name = getName(obj)
-            container = getAdapter(parent, IZopeContainer)
-            del container[name]
-
-        s = _("Deleted: ${cache_names}")
-        s.mapping = {'cache_names': ", ".join(todo)}
-        return s
-
-    def getConfigs(self):
-        L = []
-        for name in self.context.listRegistrationNames():
-            cr = self.context.queryRegistrations(name)
-            active = cr.active()
-            d = {"name": name,
-                 "url": "",
-                 "configurl": ("@@configureCache.html?name=%s" % name),
-                 }
-            if active is not None:
-                d["url"] = str(getView(active.getComponent(),
-                                       "absolute_url",
-                                       self.request))
-            L.append((name, d))
-        L.sort()
-        return [d for name, d in L]
-
-class ConfigureCache:
-
-    def update(self):
-        cr = self.context.queryRegistrations(self.request['name'])
-        form = getView(cr, "ChangeRegistrations", self.request)
-        form.update()
-        return form
-
-class Registered:
-    """View for displaying the registrations for a cache."""
-
-    def uses(self):
-        """Get a sequence of registration summaries."""
-        component = self.context
-        useconfig = getAdapter(component, IRegistered)
-        result = []
-        for path in useconfig.usages():
-            config = traverse(component, path)
-            url = getView(config, 'absolute_url', self.request)
-            result.append({'name': config.name,
-                           'path': path,
-                           'url': url(),
-                           'status': config.status,
-                           })
-        return result
 
-class AddCacheRegistration(AddComponentRegistration):
-    pass
+    def getInheritedCaches(self):
+        caches = []
+        next = queryNextService(self.context, Utilities)
+        while next is not None:
+            matching = next.getRegisteredMatching(ICache)
+            for match in matching:
+                caches.append(self.buildInfo(match))
+            next = queryNextService(next, Utilities)
+        return caches
+
+
+    def buildInfo(self, match):
+        info = {}
+        info['id'] = match[1]
+        info['url'] = str(zapi.getView(match[2].active().getComponent(),
+                                       'absolute_url', self.request))
+
+        return info
+
+
+class CacheAdding(ComponentAdding):
+
+    menu_id = "add_cache"
+
+    def add(self, content):
+        if not ICache.isImplementedBy(content):
+            raise TypeError("%s is not a Cache" % content)
+
+        return zapi.ContextSuper(CacheAdding, self).add(content)


=== Zope3/src/zope/app/browser/services/cache.zcml 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/services/cache.zcml:1.7	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/cache.zcml	Tue Aug 19 13:34:02 2003
@@ -2,56 +2,49 @@
 
 <!-- Browser directives for the cache service -->
 
+  <menuItem
+      menu="add_component"
+      for="zope.app.interfaces.container.IAdding"
+      action="../AddCache"
+      title="Cache"
+      description="Takes you to a menu of Caches to add"
+      permission="zope.ManageServices" />
+
+  <menuItem
+      for="zope.app.interfaces.services.cache.ILocalCachingService"
+      menu="zmi_actions" title="Add Cache"
+      action="../AddCache"
+      permission="zope.ManageServices" />
+
+  <view
+      for="zope.app.interfaces.services.folder.ISiteManagementFolder"
+      name="AddCache"
+      class=".cache.CacheAdding"
+      permission="zope.ManageContent">
+      
+    <page name="index.html"  attribute="index"/>
+    <page name="action.html" attribute="action" />
+
+  </view>
+
   <!-- "Add service" menu entry to add a cache service.
        The action attribute matches a factory id defined in
        zope/app/services/configure.zcml. -->
   <menuItem
       for="zope.app.interfaces.container.IAdding"
       menu="add_service" title="Caching Service"
-      action="CachingService"
-      permission="zope.ManageServices"
-      description="A Persistent Caching Service for TTW development" />
+      description="A Persistent Caching Service for TTW development"
+      action="zope.services.CachingService"
+      permission="zope.ManageServices" />
 
   <!-- ZMI tab named "Caches" for the cache service -->
   <page
-      for="zope.app.services.cache.ILocalCachingService"
+      for="zope.app.interfaces.services.cache.ILocalCachingService"
       name="index.html"
       template="caches.pt"
       class=".cache.Caches"
       permission="zope.ManageServices"
       menu="zmi_views" title="Caches" />
 
-<!-- Browser directives for configuring individual cache objects -->
-
-  <!-- Configuration page for cache objects.  You get here by
-       clicking on the (configure) link for a particular cache
-       in the "Caches" tab of the cache service.  It shows
-       a menu of different registrations, at most one of which
-       is active.  You can activate a different registration, or
-       click on an individual registration to edit it.
-       (Note that this page doesn't really apply to a single cache,
-       it applies to a single cache name. -->
-  <page
-      for="zope.app.services.cache.ILocalCachingService"
-      name="configureCache.html"
-      template="configureCache.pt"
-      class=".cache.ConfigureCache"
-      permission="zope.ManageServices" />
-
-  <!-- When creating a new cache object, you are taken to this
-       form to configure it.  The form lets you choose a name,
-       an interface, a permission, and a registration status
-       (Unregistered, Registered or Active). -->
-  <addform
-      label="New Cache Registration"
-      for="zope.app.interfaces.cache.cache.ICache"
-      name="addRegistration.html"
-      schema="zope.app.interfaces.services.cache.ICacheRegistration"
-      class=".cache.AddCacheRegistration"
-      permission="zope.ManageServices"
-      content_factory="zope.app.services.cache.CacheRegistration"
-      arguments="name componentPath"
-      set_after_add="status"
-      fields="name componentPath permission status" />
 
 </configure>


=== Zope3/src/zope/app/browser/services/caches.pt 1.12 => 1.13 ===
--- Zope3/src/zope/app/browser/services/caches.pt:1.12	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/caches.pt	Tue Aug 19 13:34:02 2003
@@ -1,63 +1,25 @@
 <html metal:use-macro="context/@@standard_macros/page">
 <body>
-<div metal:fill-slot="body"
-     tal:define="message view/update; configs view/getConfigs">
+<div metal:fill-slot="body">
 
-  <h2 i18n:translate="">Caches registered in this cache service:</h2>
-
-  <div class="message" tal:condition="message">
-    <span tal:replace="message">view/update message here</span>
-    <br /><br />
-    <i><a href="" i18n:translate="">(click to clear message)</a></i>
-  </div>
-
-  <p tal:condition="not:configs">None</p>
-
-  <form method="POST" action="index.html" tal:condition="configs">
-
-    <table>
-      <tr tal:repeat="config configs">
-        <td><input type="checkbox" name="selected:list"
-                   tal:attributes="value config/name" />
-        </td>
-        <td>
-
-          <a href="."
-             tal:condition="config/url"
-             tal:attributes="href config/url">
-             <span tal:replace="config/name" />
-          </a>
-
-          <span tal:condition="not:config/url">
-            <span tal:replace="config/name" />
-            <span i18n:translate="">(inactive)</span>
-          </span>
-
-        </td>
-        <td>
-          <a href="."
-             tal:attributes="href config/configurl"
-             i18n:translate=""
-             >(change registration)</a>
-        </td>
-      </tr>
-    </table>
-
-    <input type="submit" name="Activate" value="Activate" 
-           i18n:attributes="value activate-button"/>
-    <input type="submit" name="Deactivate" value="Deactivate"
-           i18n:attributes="value deactivate-button"/>
-    &nbsp;
-    <input type="submit" name="Delete" value="Delete"
-           i18n:attributes="value delete-button"/>
-    &nbsp;
-    <input type="submit" name="Refresh" value="Refresh"
-           i18n:attributes="value refresh-button"/>
-
-  </form>
-
-  <p><a href="../AddCache" i18n:translate="">
-    Add a cache to this cache service</a></p>
+  <h2 i18n:translate="">Local Caches</h2>
+  <ul>
+    <li tal:repeat="cache view/getLocalCaches">
+      <a href="" tal:attributes="href cache/url">
+        <b tal:content="cache/id" />
+      </a>
+    </li>
+  </ul>
+  <a href="../AddCache">Add Cache</a>
+
+  <h2 i18n:translate="">Inherited Caches</h2>
+  <ul>
+    <li tal:repeat="cache view/getInheritedCaches">
+      <a href="" tal:attributes="href cache/url">
+        <b tal:content="cache/id" />
+      </a>
+    </li>
+  </ul>
 
 </div>
 </body>


=== Zope3/src/zope/app/browser/services/configure.zcml 1.70 => 1.71 ===
--- Zope3/src/zope/app/browser/services/configure.zcml:1.70	Tue Aug 19 09:14:47 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Tue Aug 19 13:34:02 2003
@@ -453,21 +453,7 @@
     <page name="index.html"  attribute="index"  />
     <page name="action.html" attribute="action" />
 
-  </view>
-
-<!-- "Add Cache" menu -->
-
-  <view
-    name="AddCache"
-     for="zope.app.interfaces.services.folder.ISiteManagementFolder"
-     permission="zope.ManageServices"
-     class="zope.app.browser.services.service.CacheAdding">
-
-    <page name="index.html"  attribute="index"  />
-    <page name="action.html" attribute="action" />
-
-  </view>
-    
+  </view>    
 
 <!-- Bundles -->
 


=== Zope3/src/zope/app/browser/services/connection.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/browser/services/connection.py:1.16	Tue Aug 19 09:14:47 2003
+++ Zope3/src/zope/app/browser/services/connection.py	Tue Aug 19 13:34:02 2003
@@ -16,6 +16,7 @@
 $Id$
 """
 from zope.app import zapi
+from zope.app.browser.services.service import ComponentAdding
 from zope.app.component.nextservice import queryNextService
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
@@ -53,7 +54,6 @@
         info['dsn'] = match[2].active().getComponent().dsn    
         return info
 
-from zope.app.browser.services.service import ComponentAdding
 
 class ConnectionAdding(ComponentAdding):
 


=== Zope3/src/zope/app/browser/services/connection.zcml 1.11 => 1.12 ===
--- Zope3/src/zope/app/browser/services/connection.zcml:1.11	Tue Aug 19 09:14:47 2003
+++ Zope3/src/zope/app/browser/services/connection.zcml	Tue Aug 19 13:34:02 2003
@@ -3,12 +3,18 @@
 <!-- Browser directives for the connection service -->
 
   <menuItem
-    menu="add_component"
-    for="zope.app.interfaces.container.IAdding"
-    action="../AddSQLConnection"
-    title="SQL Connection"
-    description="Takes you to a menu of SQL Connections to add"
-    permission="zope.ManageServices" />
+     menu="add_component"
+     for="zope.app.interfaces.container.IAdding"
+     action="../AddSQLConnection"
+     title="SQL Connection"
+     description="Takes you to a menu of SQL Connections to add"
+     permission="zope.ManageServices" />
+
+  <menuItem
+      for="zope.app.interfaces.services.connection.ILocalConnectionService"
+      menu="zmi_actions" title="Add DA"
+      action="../AddSQLConnection"
+      permission="zope.ManageServices" />
 
   <view
       for="zope.app.interfaces.services.folder.ISiteManagementFolder"
@@ -20,12 +26,6 @@
     <page name="action.html" attribute="action" />
       
   </view>
-
-  <menuItem
-      for="zope.app.interfaces.services.connection.ILocalConnectionService"
-      menu="zmi_actions" title="Add DA"
-      action="../AddSQLConnection"
-      permission="zope.ManageServices" />
 
   <!-- "Add service" menu entry to add a connection service.
        The action attribute matches a factory name defined in


=== Zope3/src/zope/app/browser/services/service.py 1.37 => 1.38 ===
--- Zope3/src/zope/app/browser/services/service.py:1.37	Tue Aug 19 09:14:47 2003
+++ Zope3/src/zope/app/browser/services/service.py	Tue Aug 19 13:34:02 2003
@@ -89,6 +89,7 @@
 
         return zapi.ContextSuper(ServiceAdding, self).add(content)
 
+
 class UtilityAdding(ComponentAdding):
     """Adding subclass used for adding utilities."""
 
@@ -100,13 +101,7 @@
         if not ILocalUtility.isImplementedBy(content):
             raise TypeError("%s is not a local utility" % content)
         return zapi.ContextSuper(UtilityAdding, self).add(content)
-
-
-class CacheAdding(ComponentAdding):
-    """Adding subclass used for adding caches."""
-
-    menu_id = "add_cache"
-
+    
 
 class AddServiceRegistration(BrowserView):
     """A view on a service implementation, used by add_svc_config.py."""

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




More information about the Zope3-Checkins mailing list