[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - IToIRegistry.py:1.1.4.8 IViewService.py:1.1.2.4 ViewService.py:1.1.2.6 __init__.py:1.1.6.12
Casey Duncan
casey_duncan@yahoo.com
Fri, 1 Feb 2002 18:37:34 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv22548/ComponentArchitecture
Modified Files:
Tag: Zope-3x-branch
IToIRegistry.py IViewService.py ViewService.py __init__.py
Log Message:
Implemented default view name handling
=== Zope3/lib/python/Zope/ComponentArchitecture/IToIRegistry.py 1.1.4.7 => 1.1.4.8 ===
'''
self._registerAll(None, provide, c, provide)
+
+class IToIDataRegistry(IToIRegistry):
+
+ def register(self, require, provide, data):
+ '''
+ Registers data for combination of a require and a
+ provide interface.
+ '''
+ self._registerAll(require, provide, data, provide)
=== Zope3/lib/python/Zope/ComponentArchitecture/IViewService.py 1.1.2.3 => 1.1.2.4 ===
"""
+ def getDefaultViewName(object, type, default=None):
+ """Look up the name of the default view for the object
+
+ A Zope.NotFoundError will be raised if the suitable
+ default view name for the object cannot be found.
+ """
+
+ def getRequestDefaultViewName(object, request, default=None):
+ """Look up the name of the default view for the object
+
+ The request must implement IViewRequest.
+
+ A Zope.NotFoundError will be raised if the suitable
+ default view name for the object cannot be found.
+ """
+
+
class IViewRequest(Interface):
"""An IViewRequest provides methods for getting view meta data.
"""
=== Zope3/lib/python/Zope/ComponentArchitecture/ViewService.py 1.1.2.5 => 1.1.2.6 ===
"""
-from IToIRegistry import IToIRegistry
+from IToIRegistry import IToIRegistry, IToIDataRegistry
from Exceptions import ComponentLookupError
from SkinService import getSkin
from IViewService import IViewService
+from Zope.Exceptions import NotFoundError
_marker = object()
@@ -26,8 +27,17 @@
def __init__(self):
self.__layers = {}
+ self.__default_view_names = IToIDataRegistry()
__implements__ = IViewService
+
+ def setDefaultViewName(self, i_required, i_provided, name):
+ '''Add name to our registry of default view names for
+ the interfaces given.
+ '''
+ self.__default_view_names.register(i_required,
+ i_provided,
+ name)
# Implementation methods for interface
# Zope.ComponentArchitecture.IViewService.
@@ -79,6 +89,25 @@
reg.register(forInterface, type, maker)
+ def getDefaultViewName(self, object, type, default=_marker):
+ '''See interface IViewService'''
+
+ name = self.__default_view_names.getForObject(object, type)
+ if name is None:
+ if default is not _marker:
+ return default
+ raise NotFoundError, \
+ 'No default view name found for object %s' % object
+ return name
+
+
+ def getRequestDefaultViewName(self, object, request, default=None):
+ '''See interface IViewService'''
+ return self.getDefaultViewName(object,
+ request.getViewType(),
+ default=default
+ )
+
def _clear(self):
self.__init__()
@@ -86,4 +115,6 @@
getView = viewService.getView
provideView = viewService.provideView
getRequestView = viewService.getRequestView
+getDefaultViewName = viewService.getDefaultViewName
+getRequestDefaultViewName = viewService.getRequestDefaultViewName
_clear = viewService._clear
=== Zope3/lib/python/Zope/ComponentArchitecture/__init__.py 1.1.6.11 => 1.1.6.12 ===
from SkinService import getSkin, defineSkin
from ViewService import getView, provideView, getRequestView
+from ViewService import getDefaultViewName, getRequestDefaultViewName
from ResourceService import getResource, provideResource, getRequestResource
def _clear():