[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/site/browser/ Tools management forms now carefully handle situation when

Dmitry Vasiliev dima at hlabs.spb.ru
Tue Jul 27 08:07:35 EDT 2004


Log message for revision 26779:
  Tools management forms now carefully handle situation when
  no tools selected.
  


Changed:
  U   Zope3/trunk/src/zope/app/site/browser/__init__.py
  U   Zope3/trunk/src/zope/app/site/browser/services.pt
  U   Zope3/trunk/src/zope/app/site/browser/tool.pt
  U   Zope3/trunk/src/zope/app/site/browser/tools.py


-=-
Modified: Zope3/trunk/src/zope/app/site/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/__init__.py	2004-07-27 08:17:15 UTC (rev 26778)
+++ Zope3/trunk/src/zope/app/site/browser/__init__.py	2004-07-27 12:07:35 UTC (rev 26779)
@@ -210,8 +210,8 @@
         doDeactivate = self.request.get("Deactivate")
         doDelete = self.request.get("Delete")
         if not todo:
-            if doDeactivate or doDelete:
-                return "Please select at least one checkbox"
+            if doActivate or doDeactivate or doDelete:
+                return _("Please select at least one checkbox")
             return None
         if doActivate:
             return self._activate(todo)

Modified: Zope3/trunk/src/zope/app/site/browser/services.pt
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/services.pt	2004-07-27 08:17:15 UTC (rev 26778)
+++ Zope3/trunk/src/zope/app/site/browser/services.pt	2004-07-27 12:07:35 UTC (rev 26779)
@@ -14,11 +14,11 @@
        <br /><br />
        <i><a href="" i18n:translate="">(click to clear message)</a></i>
     </div>
-    
+
     <p tal:condition="not:registries" i18n:translate="">
       No services are registered.
     </p>
-    
+
     <div tal:condition="registries">
       <p i18n:translate="">
          Unless a service is disabled the service name links to the
@@ -27,9 +27,9 @@
          link allows activating a different implementation or
          disabling the service altogether.
       </p>
-    
+
       <form method="POST" action="services.html">
-    
+
         <table>
           <tr tal:repeat="reg registries">
             <td><input tal:condition="reg/manageable" type="checkbox"

Modified: Zope3/trunk/src/zope/app/site/browser/tool.pt
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/tool.pt	2004-07-27 08:17:15 UTC (rev 26778)
+++ Zope3/trunk/src/zope/app/site/browser/tool.pt	2004-07-27 12:07:35 UTC (rev 26779)
@@ -14,26 +14,25 @@
                    registries view/getComponents;
                    rename_list view/renameList">
 
-    
-    <p class="message"
-       tal:condition="message"
-       tal:content="message"
-       i18n:translate="">
-      Message
-    </p>
 
+    <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:registries" i18n:translate="">
       No tools are registered.
     </p>
-    
+
     <div>
       <p i18n:translate="">
          Unless a tool is disabled the tool name links to the
          active tool. ...
       </p>
-    
+
       <form method="POST">
-    
+
         <table width="100%" tal:condition="registries">
           <tr>
             <th width="5%"> </th>

Modified: Zope3/trunk/src/zope/app/site/browser/tools.py
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/tools.py	2004-07-27 08:17:15 UTC (rev 26778)
+++ Zope3/trunk/src/zope/app/site/browser/tools.py	2004-07-27 12:07:35 UTC (rev 26779)
@@ -17,13 +17,11 @@
 """
 from zope.interface import implements, Attribute
 from zope.interface.interfaces import IInterface
-from zope.component.interfaces import IFactory
 from zope.app.pagetemplate.simpleviewclass import simple as SimpleView
 from zope.app.publisher.interfaces.browser import IBrowserView
 from zope.app import zapi
 from zope.app.copypastemove import rename
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-from zope.app.site.folder import SiteManagementFolder 
 from zope.app.servicenames import Services, Utilities
 from zope.app.utility.browser import AddRegistration
 from zope.app.utility import UtilityRegistration
@@ -32,7 +30,6 @@
 from zope.app.registration.interfaces import UnregisteredStatus
 from zope.app.registration.interfaces import RegisteredStatus
 from zope.app.registration.interfaces import ActiveStatus
-from zope.app.site.interfaces import ILocalService
 from zope.app.site.browser import ServiceAdding
 
 from zope.app.i18n import ZopeMessageIDFactory as _
@@ -43,19 +40,9 @@
 
 class IToolView(IBrowserView):
 
-    folder = Attribute("Name of the folder the tools are stored in.")
-
     title = Attribute("Title for the view.")
-
     description = Attribute("Description for the view.")
 
-    def addTool(self):
-        """Add a tool to the Site Manager.
-
-        This method is responsible of creating the correct folder, if
-        necessary, and forward the user to the adding screen.
-        """
-
     def update(self):
         """Update the data."""
 
@@ -89,25 +76,56 @@
 
         return self.request.response.redirect(url)
 
+class AbstractToolView(SimpleView):
+    """Abstract tools view."""
 
-class ServiceToolView(SimpleView):
-    """Tools view for services."""
-    implements(IToolView)
-
     index = ViewPageTemplateFile('tool.pt')
 
-    folder = None
     title = None
     description = None
 
     can_rename = False
 
-    def addTool(self):
-        if not self.folder in self.context:
-            self.context[self.folder] = SiteManagementFolder()
-        link = './%s/AddServiceTool' %self.folder
-        return self.request.response.redirect(link)
+    def update(self):
+        status = ''
+        self.renameList = []
 
+        has_key = self.request.form.has_key
+        selected = self.request.form.get('selected', [])
+        doAdd = has_key('ADD')
+        doDelete = has_key('DELETE')
+        doRename = has_key('RENAME')
+        applyRename = has_key('APPLY_RENAME')
+        doActivate = has_key('ACTIVATE')
+        doDeactivate = has_key('DEACTIVATE')
+
+        if doAdd:
+            self.add()
+        elif not selected:
+            if (doDelete or doRename or applyRename
+                or doActivate or doDeactivate):
+                status = _('Please select at least one checkbox')
+        elif doDelete:
+            self.delete()
+            status = _('Deleted selected tools.')
+        elif doRename:
+            self.renameList = selected
+        elif applyRename:
+            self.rename()
+            status = _('Renamed selected tools.')
+        elif doActivate:
+            self.activate()
+            status = _('Activated registrations.')
+        elif doDeactivate:
+            self.deactivate()
+            status = _('Deactivated registrations.')
+
+        return status
+
+class ServiceToolView(AbstractToolView):
+    """Tools view for services."""
+    implements(IToolView)
+
     def delete(self):
         for name in self.request.form['selected']:
             reg = self.context.queryRegistrations(name)
@@ -140,7 +158,7 @@
             for info in reg.info():
                 conf = info['registration']
                 conf.status = ActiveStatus
-        
+
     def deactivate(self):
         for name in self.request.form['selected']:
             reg = self.context.queryRegistrations(name)
@@ -149,32 +167,12 @@
                 conf = info['registration']
                 conf.status = RegisteredStatus
 
-    def update(self):
-        status = ''
-        self.renameList = []
-        
-        if self.request.form.has_key('ADD'):
-            self.request.response.redirect('./AddServiceTool')
-        elif self.request.form.has_key('DELETE'):
-            self.delete()
-            status = _('Deleted selected tools.')
-        elif self.request.form.has_key('APPLY_RENAME'):
-            self.rename()
-            status = _('Renamed selected tools.')         
-        elif self.request.form.has_key('REFRESH'):
-            pass
-        elif self.request.form.has_key('ACTIVATE'):
-            self.activate()
-            status = _('Activated registrations.')
-        elif self.request.form.has_key('DEACTIVATE'):
-            self.deactivate()
-            status = _('Deactivated registrations.')
-            
-        return status
-    
+    def add(self):
+        self.request.response.redirect('./AddServiceTool')
+
     def getComponents(self):
         items = []
-        
+
         for name in self.context.listRegistrationNames():
             registry = self.context.queryRegistrations(name)
 
@@ -188,7 +186,7 @@
                            'parent_url': zapi.getPath(parent),
                            'parent_name':zapi.name(parent),
                            'active':registry.info()[0]['active'] })
-        
+
         return items
 
 class ServiceToolAdding(ServiceAdding):
@@ -206,31 +204,18 @@
     def add(self, content):
         self.context = self.context[self.folder]
         return super(ServiceToolAdding, self).add(content)
-    
+
     def nextURL(self):
         return '../@@manageILocalServiceTool.html'
 
 
-class UtilityToolView(SimpleView):
+class UtilityToolView(AbstractToolView):
     """Tools view for utilities."""
 
     implements(IUtilityToolView)
 
-    index = ViewPageTemplateFile('tool.pt')
-
-    interface = None
-    folder = None
-    title = None
-    description = None
-
     can_rename = True
 
-    def addTool(self):
-        if not self.folder in self.context:
-            self.context[self.folder] = SiteManagementFolder()
-        link = './%s/AddUtilityTool?interface=%s' %(self.folder, self.interface)
-        return self.request.response.redirect(link)
-
     def delete(self):
         for name in self.request.form['selected']:
             utils = zapi.getService(Utilities)
@@ -260,7 +245,7 @@
         for name in self.request.form['old_names']:
             newname = self.request.form['new_names'][
                 self.request.form['old_names'].index(name)]
-            
+
             utils = zapi.getService('Utilities')
             reg = utils.queryRegistrations(name, self.interface)
 
@@ -281,7 +266,7 @@
             for info in reg.info():
                 conf = info['registration']
                 conf.status = ActiveStatus
-        
+
     def deactivate(self):
         for name in self.request.form['selected']:
             utils = zapi.getService('Utilities')
@@ -292,32 +277,10 @@
                 conf = info['registration']
                 conf.status = RegisteredStatus
 
-    def update(self):
-        status = ''
-        self.renameList = []
-        
-        if self.request.form.has_key('ADD'):
-            self.request.response.redirect('./Add%sTool' %
-                                           self.interface.getName())
-        elif self.request.form.has_key('DELETE'):
-            self.delete()
-            status = _('Deleted selected tools.')
-        elif self.request.form.has_key('RENAME'):
-            self.renameList = self.request.form.get('selected', [])
-        elif self.request.form.has_key('APPLY_RENAME'):
-            self.rename()
-            status = _('Renamed selected tools.')         
-        elif self.request.form.has_key('REFRESH'):
-            pass
-        elif self.request.form.has_key('ACTIVATE'):
-            self.activate()
-            status = _('Activated registrations.')
-        elif self.request.form.has_key('DEACTIVATE'):
-            self.deactivate()
-            status = _('Deactivated registrations.')
-            
-        return status
-    
+    def add(self):
+        self.request.response.redirect('./Add%sTool' %
+                                       self.interface.getName())
+
     def getComponents(self):
         utils = zapi.getService(Utilities)
         items = []
@@ -330,7 +293,7 @@
                 'name': registration.name,
                 'url': zapi.getPath(registration.component),
                 'parent_url': zapi.getPath(parent),
-                'parent_name': zapi.name(parent),                
+                'parent_name': zapi.name(parent),
                 'active': stack.active()})
 
         return items
@@ -357,14 +320,14 @@
                 content, self._addFilterInterface.getName()))
         self.context = self.context[self.folder]
         util = super(UtilityToolAdding, self).add(content)
-        
+
         # Add registration
         registration = UtilityRegistration(self.contentName,
                                            self._addFilterInterface,
                                            zapi.getPath(util))
         reg_view = AddRegistration(util, self.request)
         reg_view.add(registration)
-        
+
         return util
 
     def nextURL(self):



More information about the Zope3-Checkins mailing list