[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/service -
__init__.py:1.14
Anthony Baxter
anthony at interlink.com.au
Sun Feb 8 20:25:30 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/services/service
In directory cvs.zope.org:/tmp/cvs-serv8400
Modified Files:
__init__.py
Log Message:
Utility Adding and Service Adding now use the new-style menu items
and filter out non-(service|utility) entries. Code should be useful
for other people who want to do the same sort of thing.
ServiceAdding and UtilityAdding have a more accurate title
UtilityAdding takes the user to the registration page after adding.
Don't use the generated (crap) factory names as a base for the
name of the utility object added.
=== Zope3/src/zope/app/browser/services/service/__init__.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/browser/services/service/__init__.py:1.13 Sat Feb 7 02:21:25 2004
+++ Zope3/src/zope/app/browser/services/service/__init__.py Sun Feb 8 20:25:29 2004
@@ -55,6 +55,7 @@
def action(self, type_name, id):
# For special case of that we want to redirect to another adding view
# (usually another menu such as AddService)
+ import re
if type_name.startswith("../"):
# Special case
url = type_name
@@ -69,6 +70,14 @@
l = id.rfind('.')
if l >= 0:
id = id[l+1:]
+ # Add menus generate meaningless factory names.
+ # Skip them.
+ if re.match('^f[0-9]*$', id):
+ id = type_name[:l]
+ l = id.rfind('.')
+ if l >= 0:
+ id = id[l+1:]
+
chooser = zapi.getAdapter(self.context, INameChooser)
id = chooser.chooseName(id, None)
@@ -77,10 +86,38 @@
# As a side effect, self.added_object is set by add() above.
super(ComponentAdding, self).action(type_name, id)
+ _addFilterInterface = None
+ def addingInfo(self):
+ # A site management folder can have many things. We only want
+ # things that implement a particular interface
+ info = super(ComponentAdding, self).addingInfo()
+ if self._addFilterInterface is None:
+ return info
+ out = []
+ for item in info:
+ extra = item.get('extra')
+ if extra:
+ factoryname = extra.get('factory')
+ if factoryname:
+ factory = zapi.getFactory(self.context, factoryname)
+ intf = factory.getInterfaces()
+ if not intf.extends(self._addFilterInterface):
+ # We only skip new addMenuItem style objects
+ # that don't implement our wanted interface.
+ continue
+
+ out.append(item)
+
+ return out
+
+
class ServiceAdding(ComponentAdding):
"""Adding subclass used for adding services."""
menu_id = "add_service"
+ title = _("Add Service")
+
+ _addFilterInterface = ILocalService
def add(self, content):
# Override so as to check the type of the new object.
@@ -110,10 +147,14 @@
return content
+
class UtilityAdding(ComponentAdding):
"""Adding subclass used for adding utilities."""
menu_id = "add_utility"
+ title = _("Add Utility")
+
+ _addFilterInterface = ILocalUtility
def add(self, content):
# Override so as to check the type of the new object.
@@ -121,6 +162,16 @@
if not ILocalUtility.isImplementedBy(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()
class AddServiceRegistration(BrowserView):
More information about the Zope3-Checkins
mailing list