[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser - ChangeConfigurations.pt:1.2 ChangeConfigurations.py:1.2 ConfigurationStatusWidget.py:1.2 __init__.py:1.2 configure.zcml:1.2

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 13:36:26 -0500


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

Added Files:
	ChangeConfigurations.pt ChangeConfigurations.py 
	ConfigurationStatusWidget.py __init__.py configure.zcml 
Log Message:
Added a framework for managing configuration registration. This should
make it much easier to implement configurable services.



=== Zope3/lib/python/Zope/App/OFS/Services/Browser/ChangeConfigurations.pt 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:36:26 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/ChangeConfigurations.pt	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,32 @@
+<table width="100%">
+  <tr tal:define="message view/message" tal:condition="message">
+     <td></td>
+     <td colspan="2"><em tal:content="message">xxxx</em></td> 
+  </tr>
+  <tr tal:repeat="configuration view/configurations">          
+     <td><input type="radio" name="Roles" value="0"
+             tal:attributes="
+             name view/name;
+             value configuration/id;
+             checked configuration/active;
+             " 
+             />
+     </td>
+     <td><a href="." 
+            tal:attributes="href string:${view/configBase}/${configuration/id}"
+            tal:content="configuration/id"
+         >foo/bar</a></td>
+     <td tal:content="structure configuration/summary">
+         Configuration summary
+     </td>
+  </tr>
+  <tr>
+     <td><input type="radio" name="Roles" value="disable"
+                tal:attributes="
+                   name view/name;
+                   checked view/inactive;
+                   "
+                /></td>
+     <td><em>Disable</em></td>
+  </tr>
+</table>


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/ChangeConfigurations.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:36:26 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/ChangeConfigurations.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# Copyright (c) 2001, 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+from Zope.Publisher.Browser.BrowserView import BrowserView
+from Zope.ComponentArchitecture import getView, getServiceManager
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
+
+class ChangeConfigurations(BrowserView):
+
+    _prefix = 'configurations'
+    name = _prefix + ".active"
+    message = ''
+    configBase = ''
+    
+    def setPrefix(self, prefix):
+        self._prefix = prefix
+        self.name = prefix + ".active"
+
+    def applyUpdates(self):
+        message = ''
+        if 'submit_update' in self.request.form:
+            active = self.request.form.get(self.name)
+            if active == "disable":
+                active = self.context.active()
+                if active is not None:
+                    self.context.deactivate(active)
+                    message = "Disabled"
+            else:
+                for info in self.context.info():
+                    if info['id'] == active:
+                        if not info['active']:
+                            self.context.activate(info['configuration'])
+                            message = "Updated"
+
+        return message
+
+    def update(self):
+
+        message = self.applyUpdates()
+
+        self.configBase = str(getView(getServiceManager(self.context),
+                                      'absolute_url', self.request)
+                              ) + '/Packages'
+
+        configurations = self.context.info()
+
+        # This is OK because configurations is just a list of dicts
+        configurations = removeAllProxies(configurations)
+        
+        inactive = 1
+        for info in configurations:
+            if info['active']:
+                inactive = None
+            else:
+                info['active'] = None
+
+            info['summary'] = getView(info['configuration'],
+                                      'ConfigurationSummary',
+                                      self.request)
+
+        self.inactive = inactive
+        self.configurations = configurations
+
+        self.message = message


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/ConfigurationStatusWidget.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:36:26 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/ConfigurationStatusWidget.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# 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.
+# 
+##############################################################################
+"""Configuration Browser Views
+
+XXX longer description goes here.
+
+$Id$
+"""
+__metaclass__ = type
+
+from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
+from Zope.App.OFS.Services.ConfigurationInterfaces \
+     import Active, Registered, Unregistered
+
+class ConfigurationStatusWidget(BrowserWidget):
+
+    def __call__(self):
+        checked = self._showData() or Unregistered        
+        result = [
+            ('<input type="radio" name="%s" value="%s"%s> %s'
+             % (self.name, v, (v == checked and ' checked' or ''), v)
+             )
+            for v in (Unregistered, Registered, Active)
+            ]
+        return '<br />'.join(result)
+    


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/__init__.py 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:36:26 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/__init__.py	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,14 @@
+##############################################################################
+#
+# Copyright (c) 2001, 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.
+# 
+##############################################################################
+


=== Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Sat Nov 30 13:36:26 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/Browser/configure.zcml	Sat Nov 30 13:35:55 2002
@@ -0,0 +1,24 @@
+<zope:zopeConfigure
+   xmlns:zope='http://namespaces.zope.org/zope'
+   xmlns="http://namespaces.zope.org/browser"
+   package="Zope.App.OFS.Services"
+   >
+
+<view
+    for=".ConfigurationInterfaces.IConfigurationStatus"
+    name="widget"
+    factory=".Browser.ConfigurationStatusWidget."
+    allowed_interface="Zope.App.Forms.Views.Browser.IBrowserWidget."
+    permission="Zope.ManageServices"
+    />
+
+<view
+    for=".ConfigurationInterfaces.IConfigurationRegistry"
+    name="ChangeConfigurations"
+    template="Browser/ChangeConfigurations.pt"
+    class=".Browser.ChangeConfigurations."
+    allowed_interface="Zope.App.Forms.Browser.IFormCollaborationView."
+    permission="Zope.ManageServices"
+    />
+
+</zope:zopeConfigure>