[Zope3-checkins] CVS: Zope3/src/zope/app/site/browser - tools.py:1.3

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Mar 21 19:52:27 EST 2004


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

Modified Files:
	tools.py 
Log Message:


Implemented support for Add, Delete, Rename, Activate, Deactivate.



Implemented servicetool support.




=== Zope3/src/zope/app/site/browser/tools.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/site/browser/tools.py:1.2	Sun Mar 21 12:09:41 2004
+++ Zope3/src/zope/app/site/browser/tools.py	Sun Mar 21 19:52:27 2004
@@ -24,11 +24,22 @@
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.site.folder import SiteManagementFolder 
 from zope.app.servicenames import Services
+from zope.app.utility.browser import AddRegistration
+from zope.app.utility import UtilityRegistration
+from zope.app.site.browser import ComponentAdding
+from zope.app.site.folder import SiteManagementFolder
+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.copypastemove import rename
+from zope.app.site.browser import ServiceAdding
+
 
 class IToolType(IInterface):
     """Interfaces implementing the tool type are considered tools."""
 
-class IToolsView(IBrowserView):
+class IToolView(IBrowserView):
 
     folder = Attribute("Name of the folder the tools are stored in.")
 
@@ -50,7 +61,7 @@
         """Return a list of components."""
 
 
-class IUtilityToolsView(IToolsView):
+class IUtilityToolView(IToolView):
 
     interface = Attribute("Interface the utility provides.")
 
@@ -75,11 +86,132 @@
 
         return self.request.response.redirect(url)
 
+
+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 delete(self):
+        for name in self.request.form['selected']:
+            reg = self.context.queryRegistrations(name)
+
+            del_objs = []
+
+            # Delete registrations
+            for info in reg.info():
+                conf = info['registration']
+                obj = conf.getComponent()
+                conf.status = UnregisteredStatus
+                reg_folder = zapi.getParent(conf)
+                name = zapi.name(conf)
+                del reg_folder[name]
+                if obj not in [c.getComponent()
+                               for c in reg_folder.values()]:
+                    del_objs.append(obj)
+
+            # Delete object, if no other registration is available.
+            for obj in del_objs:
+                parent = zapi.getParent(obj)
+                name = zapi.name(obj)
+                del parent[name]
+
+
+    def activate(self):
+        for name in self.request.form['selected']:
+            reg = self.context.queryRegistrations(name)
+            # Activate registrations
+            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)
+            # Deactivate registrations
+            for info in reg.info():
+                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 getComponents(self):
+        items = []
+        
+        for name in self.context.listRegistrationNames():
+            registry = self.context.queryRegistrations(name)
+
+            configobj = registry.info()[0]['registration']
+            component = configobj.getComponent()
+            url = str(
+                zapi.getView(component, 'absolute_url', self.request))
+            parent = zapi.getParent(component)
+            items.append( {'name': name,
+                           'url': url,
+                           'parent_url': zapi.getPath(parent),
+                           'parent_name':zapi.name(parent),
+                           'active':registry.info()[0]['active'] })
         
-class UtilityToolsView(SimpleView):
+        return items
+
+class ServiceToolAdding(ServiceAdding):
+    """Adding subclass used for adding utilities."""
+
+    title = "Add Service Tool"
+    folder = "tools"
+
+    def addingInfo(self):
+        if self.folder not in self.context:
+            self.context[self.folder] = SiteManagementFolder()
+        self.context = self.context[self.folder]
+        return super(ServiceToolAdding, self).addingInfo()
+
+    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):
     """Tools view for utilities."""
 
-    implements(IUtilityToolsView)
+    implements(IUtilityToolView)
 
     index = ViewPageTemplateFile('tool.pt')
 
@@ -88,14 +220,100 @@
     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(self, 'Utilities')
+            reg = utils.queryRegistrations(name, self.interface)
+
+            del_objs = []
+
+            # Delete registrations
+            for info in reg.info():
+                conf = info['registration']
+                obj = conf.getComponent()
+                conf.status = UnregisteredStatus
+                reg_folder = zapi.getParent(conf)
+                name = zapi.name(conf)
+                del reg_folder[name]
+                if obj not in [c.getComponent()
+                               for c in reg_folder.values()]:
+                    del_objs.append(obj)
+
+            # Delete object, if no other registration is available.
+            for obj in del_objs:
+                parent = zapi.getParent(obj)
+                name = zapi.name(obj)
+                del parent[name]
+
+    def rename(self):
+        for name in self.request.form['old_names']:
+            newname = self.request.form['new_names'][
+                self.request.form['old_names'].index(name)]
+            
+            utils = zapi.getService(self, 'Utilities')
+            reg = utils.queryRegistrations(name, self.interface)
+
+            # Rename registrations
+            for info in reg.info():
+                conf = info['registration']
+                orig_status = conf.status
+                conf.status = UnregisteredStatus
+                conf.name = newname
+                conf.status = orig_status
+
+    def activate(self):
+        for name in self.request.form['selected']:
+            utils = zapi.getService(self, 'Utilities')
+            reg = utils.queryRegistrations(name, self.interface)
+
+            # Activate registrations
+            for info in reg.info():
+                conf = info['registration']
+                conf.status = ActiveStatus
+        
+    def deactivate(self):
+        for name in self.request.form['selected']:
+            utils = zapi.getService(self, 'Utilities')
+            reg = utils.queryRegistrations(name, self.interface)
+
+            # Deactivate registrations
+            for info in reg.info():
+                conf = info['registration']
+                conf.status = RegisteredStatus
+
     def update(self):
-        return ''
+        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 getComponents(self):
         utils = zapi.getService(self.context, 'Utilities')
@@ -114,53 +332,36 @@
         return items
 
 
-class UtilityToolsViewFactory(object):
-    """A factory that creates a tools view for a utility"""
-    implements(IFactory)
-
-    def __init__(self, interface, folder="tools", title=None, description=None):
-        self._interface = interface
-        self._folder = folder
-        self._title = title
-        self._description = description
-
-        # See IFactory
-        self.title = "Tools for '%s' Utility" %(interface.getName())
-        self.description = self.title
-
-    def __call__(self, context, request):
-        tools = UtilityToolsView(context, request)
-        tools.interface = self._interface
-        tools.folder = self._folder
-        tools.title = self._title
-        tools.description = self._description
-        return tools
+class UtilityToolAdding(ComponentAdding):
+    """Adding subclass used for adding utilities."""
 
-    def getInterfaces(self):
-        return implementedBy(self._class)
+    menu_id = None
+    title = "Add Tool"
+    folder = "tools"
+    _addFilterInterface = None
 
 
-# class UtilityToolAdding(ComponentAdding):
-#     """Adding subclass used for adding utilities."""
-# 
-#     menu_id = None
-#     title = "Add Utility"
-# 
-#     _addFilterInterface = ILocalUtility
-# 
-#     def add(self, content):
-#         # Override so as to check the type of the new object.
-#         # XXX This wants to be generalized!
-#         if not ILocalUtility.providedBy(content):
-#             raise TypeError("%s is not a local utility" % content)
-#         return super(UtilityAdding, self).add(content)
-# 
-#     def nextURL(self):
-#         v = zapi.queryView(
-#             self.added_object, "addRegistration.html", self.request)
-#         if v is not None:
-#             url = str(
-#                 zapi.getView(self.added_object, 'absolute_url', self.request))
-#             return url + "/addRegistration.html"
-# 
-#         return super(UtilityAdding, self).nextURL()
+    def addingInfo(self):
+        if self.folder not in self.context:
+            self.context[self.folder] = SiteManagementFolder()
+        self.context = self.context[self.folder]
+        return super(UtilityToolAdding, self).addingInfo()
+
+    def add(self, content):
+        if not self._addFilterInterface.providedBy(content):
+            raise TypeError("%s is not a %s" %(
+                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(content, self.request)
+        reg_view.add(registration)
+        
+        return util
+
+    def nextURL(self):
+        return '../@@manage%sTool.html' %self._addFilterInterface.getName()




More information about the Zope3-Checkins mailing list