[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.42 interface.py:1.8 view.py:1.28
Jeremy Hylton
jeremy@zope.com
Tue, 24 Jun 2003 11:38:35 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv21560/src/zope/app/services
Modified Files:
configure.zcml interface.py view.py
Log Message:
Hook up the local and global view services for interface queries.
getRegistrationsForInterface() propagates the query to the next service if it also supports IInterfaceBasedRegistry.
Add an adapter for the GlobalViewService to support IInterfaceBasedRegistry. The adapter goes here, because the global service is in zope.component, which shouldn't depend on zope.app.
Convert the global views to registrations so that they can be passed back from getRegistrationsForInterface().
=== Zope3/src/zope/app/services/configure.zcml 1.41 => 1.42 ===
--- Zope3/src/zope/app/services/configure.zcml:1.41 Mon Jun 23 18:46:17 2003
+++ Zope3/src/zope/app/services/configure.zcml Tue Jun 24 11:38:04 2003
@@ -77,6 +77,13 @@
/>
</content>
+<adapter
+ for="zope.component.interfaces.IGlobalViewService"
+ provides="zope.app.interfaces.services.interface.IInterfaceBasedRegistry"
+ factory=".view.RegistrationAdapter"
+ />
+
+
<!-- Page Templates -->
<content class="zope.app.services.zpt.ZPTTemplate">
=== Zope3/src/zope/app/services/interface.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/services/interface.py:1.7 Sun Jun 22 16:23:26 2003
+++ Zope3/src/zope/app/services/interface.py Tue Jun 24 11:38:04 2003
@@ -83,4 +83,3 @@
# Return id, interface pairs for all items matching criteria.
next = getNextService(self, Interfaces)
return next.items(search_string, base)
-
=== Zope3/src/zope/app/services/view.py 1.27 => 1.28 ===
--- Zope3/src/zope/app/services/view.py:1.27 Mon Jun 23 12:38:03 2003
+++ Zope3/src/zope/app/services/view.py Tue Jun 24 11:38:04 2003
@@ -23,12 +23,16 @@
from zope.publisher.interfaces.browser import IBrowserPresentation
-from zope.component.interfaces import IViewService
+from zope.component.interfaces import IViewService, IGlobalViewService
from zope.component.exceptions import ComponentLookupError
+
+from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.services.interface import IInterfaceBasedRegistry
-from zope.app.interfaces.services.registration import IRegistry
+from zope.app.interfaces.services.registration \
+ import IRegistry, IRegistration, ActiveStatus
from zope.app.services.registration import RegistrationStack
from zope.app.services.registration import SimpleRegistration
+from zope.app.services.servicenames import Views
from zope.app.component.nextservice import getNextService
from zope.app import zapi
from zope.interface import implements
@@ -38,6 +42,7 @@
from zope.proxy import removeAllProxies
from zope.exceptions import NotFoundError
+from zope.app.interfaces.services.interface import IInterfaceBasedRegistry
from zope.app.interfaces.services.view import IViewRegistration
from zope.app.interfaces.services.view import IPageRegistration
from zope.app.interfaces.services.view import ILocalViewService
@@ -47,7 +52,8 @@
class ViewService(Persistent):
- implements(IViewService, ILocalViewService, IRegistry, ISimpleService)
+ implements(IViewService, ILocalViewService, IRegistry, ISimpleService,
+ IInterfaceBasedRegistry)
def __init__(self):
self._layers = PersistentDict()
@@ -142,7 +148,7 @@
view = registry.active().getView(object, request)
return view
- views = getNextService(self, 'Views')
+ views = getNextService(self, Views)
return views.queryView(object, name, request, default)
@@ -152,8 +158,8 @@
name = self.queryDefaultViewName(object, request)
if name is None:
- raise NotFoundError, \
- 'No default view name found for object %s' % object
+ raise NotFoundError(
+ "No default view name found for object %s" % object)
return name
@@ -161,7 +167,7 @@
"See IViewService"
# XXX: need to do our own defaults as well.
- views = getNextService(self, 'Views')
+ views = getNextService(self, Views)
return views.queryDefaultViewName(object, request, default)
def getRegisteredMatching(self, required_interfaces=None,
@@ -204,13 +210,62 @@
for info in reg.info():
yield info["registration"]
+ next = getNextService(self, Views)
+ next = zapi.queryAdapter(next, IInterfaceBasedRegistry)
+ if next is None:
+ return
+ for r in next.getRegistrationsForInterface(iface):
+ yield r
+
+class RegistrationAdapter:
+ """Adapter to create registrations from factory chains."""
+
+ implements(IInterfaceBasedRegistry)
+ __used_for__ = IGlobalViewService
+
+ def __init__(self, gvs):
+ self.gvs = gvs
+
+ def getRegistrationsForInterface(self, iface):
+ for t in self.gvs.getRegisteredMatching(required_interfaces=[iface]):
+ yield GlobalViewRegistration(*t)
+
+class GlobalViewRegistration:
+ """Registrations representing global view service thingies."""
+
+ implements(IRegistration)
+
+ serviceType = Views
+ status = ActiveStatus
+
+ def __init__(self, req, ptype, factories, layer, viewName):
+ self.forInterface = req
+ self.ptype = ptype
+ self.factories = factories
+ self.layer = layer
+ self.viewName = viewName
+
+ def usageSummary(self):
+ if self.forInterface is None:
+ ifname = _("(Anything)")
+ else:
+ ifname = self.forInterface.__name__
+ L = [self.viewName, self.ptype.__name__, _("View"), _("for"), ifname]
+ if self.layer and self.layer != "default":
+ L.extend([_("in layer"), self.layer])
+ return " ".join(L)
+
+ def implementationSummary(self):
+ # XXX This should report the ZCML that it came from.
+ return _("Registered by ZCML")
+
class ViewRegistration(SimpleRegistration):
implements(IViewRegistration)
- serviceType = 'Views'
+ serviceType = Views
- _what = "View" # For usageSummary(); subclass may override
+ _what = _("View") # For usageSummary(); subclass may override
def __init__(self,
forInterface, viewName, presentationType,
@@ -230,13 +285,16 @@
getView = zapi.ContextMethod(getView)
def usageSummary(self):
- # XXX L10N This should be localizable.
- ifname = getattr(self.forInterface, '__name__', "(Anything)")
- s = "%s %s for %s" % (self.viewName, self._what, ifname)
+ if self.forInterface is None:
+ ifname = _("(Anything)")
+ else:
+ ifname = self.forInterface.__name__
+ pname = self.presentationType.__name__
+ L = [self.viewName, _("for"), pname, self._what, ifname]
if self.layer and self.layer != "default":
- s = "%s in layer %s" % (s, self.layer)
- return s
-
+ L.extend([_("in layer"), self.layer])
+ return " ".join(L)
+
class PageRegistration(ViewRegistration):
implements(IPageRegistration)
@@ -244,7 +302,7 @@
# We only care about browser pages
presentationType = IBrowserPresentation
- _what = "Page" # For usageSummary()
+ _what = _("Page") # For usageSummary()
def __init__(self,
forInterface, viewName, permission,