[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - view.py:1.12 views.pt:1.2

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


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

Modified Files:
	view.py views.pt 
Log Message:
Add an "Activate" button to the Views service.


=== Zope3/src/zope/app/browser/services/view.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/browser/services/view.py:1.11	Thu May  1 10:40:24 2003
+++ Zope3/src/zope/app/browser/services/view.py	Thu May  1 10:46:26 2003
@@ -39,7 +39,8 @@
 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.interfaces.services.configuration \
+     import Unregistered, Registered, Active
 from zope.app.traversing import traverse, getPath, getParent, objectName
 
 # XXX These are not used in this module, but are referenced in configure.zcml.
@@ -81,12 +82,15 @@
         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 doDeactivate or doDelete:
+            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:
@@ -108,6 +112,26 @@
                                                    layerName)
         # We only want exact matches on 'forInterface'
         return [info for info in infos if info[0] == forInterface]
+
+    def _activate(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 None:
+                    assert registry
+                    # Activate the first registered configuration
+                    obj = registry.info()[0]['configuration']
+                    obj.status = Active
+                    done.append(key)
+        if done:
+            return "Activated: " + ", ".join(done)
+        else:
+            return "None of the checked utilities were inactive"
 
     def _deactivate(self, todo):
         done = []


=== Zope3/src/zope/app/browser/services/views.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/browser/services/views.pt:1.1	Wed Apr 30 18:06:31 2003
+++ Zope3/src/zope/app/browser/services/views.pt	Thu May  1 10:46:26 2003
@@ -44,6 +44,7 @@
     </tbody>
   </table>
 
+  <input type="submit" name="Activate" value="Activate" />
   <input type="submit" name="Deactivate" value="Deactivate" />
   <input type="submit" name="Delete" value="Delete" />
   <input type="submit" name="Refresh" value="Refresh" />