[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - useconfiguration.py:1.7 utilities.pt:1.9

Guido van Rossum guido@python.org
Thu, 1 May 2003 12:28:29 -0400


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

Modified Files:
	useconfiguration.py utilities.pt 
Log Message:
More UI tweaks; use usageSummary() more consistently; add Activate buttons.


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.6	Wed Apr 30 11:15:30 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py	Thu May  1 12:28:28 2003
@@ -20,7 +20,8 @@
 from zope.app.browser.services.configuration import AddComponentConfiguration
 from zope.app.form.widget import CustomWidget
 from zope.app.interfaces.container import IZopeContainer
-from zope.app.interfaces.services.configuration import Unregistered, Registered
+from zope.app.interfaces.services.configuration \
+     import Unregistered, Registered, Active
 from zope.app.traversing import getPath, getParent, objectName
 from zope.component import getServiceManager, getView, getAdapter
 from zope.interface.implements import flattenInterfaces
@@ -77,10 +78,11 @@
         In that case, issue a message.
         """
         selected = self.request.get("selected")
+        doActivate = self.request.get("Activate")
         doDeactivate = self.request.get("Deactivate")
         doDelete = self.request.get("Delete")
         if not selected:
-            if doDeactivate or doDelete:
+            if doActivate or doDeactivate or doDelete:
                 return "Please select at least one checkbox"
             return None
         sm = getServiceManager(self.context)
@@ -89,11 +91,28 @@
             name, ifacename = key.split(":", 1)
             iface = sm.resolve(ifacename)
             todo.append((key, name, iface))
+        if doActivate:
+            return self._activate(todo)
         if doDeactivate:
             return self._deactivate(todo)
         if doDelete:
             return self._delete(todo)
 
+    def _activate(self, todo):
+        done = []
+        for key, name, iface in todo:
+            registry = self.context.queryConfigurations(name, iface)
+            obj = registry.active()
+            if obj is None:
+                # Activate the first registered configuration
+                obj = registry.info()[0]['configuration']
+                obj.status = Active
+                done.append(obj.usageSummary())
+        if done:
+            return "Activated: " + ", ".join(done)
+        else:
+            return "All of the checked utilities were already active"
+
     def _deactivate(self, todo):
         done = []
         for key, name, iface in todo:
@@ -101,7 +120,7 @@
             obj = registry.active()
             if obj is not None:
                 obj.status = Registered
-                done.append(key)
+                done.append(obj.usageSummary())
         if done:
             return "Deactivated: " + ", ".join(done)
         else:
@@ -112,8 +131,9 @@
         for key, name, iface in todo:
             registry = self.context.queryConfigurations(name, iface)
             assert registry
-            if registry.active() is not None:
-                errors.append(key)
+            obj = registry.active()
+            if obj is not None:
+                errors.append(obj.usageSummary())
                 continue
         if errors:
             return ("Can't delete active utilit%s: %s; "
@@ -122,13 +142,18 @@
 
         # 1) Delete the registrations
         services = {}
+        done = []
         for key, name, iface in todo:
             registry = self.context.queryConfigurations(name, iface)
             assert registry
             assert registry.active() is None # Phase error
+            first = True
             for info in registry.info():
                 conf = info['configuration']
                 obj = conf.getComponent()
+                if first:
+                    done.append(conf.usageSummary())
+                    first = False
                 path = getPath(obj)
                 services[path] = obj
                 conf.status = Unregistered
@@ -144,16 +169,19 @@
             container = getAdapter(parent, IZopeContainer)
             del container[name]
 
-        return "Deleted: %s" % ", ".join([key for key, name, iface in todo])
+        return "Deleted: %s" % ", ".join(done)
 
     def getConfigs(self):
         L = []
         for iface, name, cr in self.context.getRegisteredMatching():
-            active = cr.active()
+            active = obj = cr.active()
+            if obj is None:
+                obj = cr.info()[0]['configuration'] # Pick a representative
             ifname = _interface_name(iface)
             d = {"interface": ifname,
                  "name": name,
                  "url": "",
+                 "summary": obj.usageSummary(),
                  "configurl": ("@@configureutility.html?interface=%s&name=%s"
                                % (ifname, name)),
                  }


=== Zope3/src/zope/app/browser/services/utility/utilities.pt 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/services/utility/utilities.pt:1.8	Wed Apr 30 16:15:47 2003
+++ Zope3/src/zope/app/browser/services/utility/utilities.pt	Thu May  1 12:28:28 2003
@@ -23,22 +23,13 @@
                  "value string:${config/name}:${config/interface}" />
       </td>
       <td>
-
         <a href="."
            tal:condition="config/url"
            tal:attributes=
-	       "href string:${config/url}/@@SelectedManagementView.html" >
-          <span tal:replace="string:${config/name}:${config/interface}" />
-        </a>
-
-        <span tal:condition="not:config/url">
-          <span tal:replace="config/interface" />
-          <span tal:condition="config/name" i18n:translate="">
-            named <span tal:replace="config/name" i18n:name="utility_name" />
-          </span>
-          <span i18n:translate="">(inactive)</span>
-        </span>
-
+	       "href string:${config/url}/@@SelectedManagementView.html"
+           tal:content="config/summary" />
+        <span tal:condition="not:config/url"
+              tal:replace="config/summary" />
       </td>
       <td>
         <a href="."
@@ -49,8 +40,11 @@
     </tr>
   </table>
 
+  <input type="submit" name="Activate" value="Activate" />
   <input type="submit" name="Deactivate" value="Deactivate" />
+  &nbsp;
   <input type="submit" name="Delete" value="Delete" />
+  &nbsp;
   <input type="submit" name="Refresh" value="Refresh" />
 
 </form>