[Zope3-checkins] CVS: Zope3/src/zope/component - presentation.py:1.2.2.1

Christian Zagrodnick cvs-admin at zope.org
Sat Dec 6 13:29:23 EST 2003


Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv16289/src/zope/component

Modified Files:
      Tag: gotcha-usage-branch
	presentation.py 
Log Message:
finished the support of 'usage' in page templates (or better views)
 - repaired editForm
 - added to addForm
 - added <usage name=.. /> zcml directive
 - directives that rely on usage check for existing usages
 - asserting that a usage can only be defined once
 - tried use of usage in container/add.pt



=== Zope3/src/zope/component/presentation.py 1.2 => 1.2.2.1 ===
--- Zope3/src/zope/component/presentation.py:1.2	Fri Nov 21 12:09:26 2003
+++ Zope3/src/zope/component/presentation.py	Sat Dec  6 13:29:22 2003
@@ -29,7 +29,7 @@
 
 
 class IGlobalPresentationService(zope.interface.Interface):
-    """Provide abaility to update the flobal presentation service
+    """Provide ability to update the global presentation service
     """
 
     def defineSkin(name, layers):
@@ -51,6 +51,10 @@
     def defineLayer(name):
         """Define a layer
         """
+    
+    def defineUsage(name):
+        """Define a usage
+        """
 
     def provideAdapter(request_type, factories, name='', contexts=(),
                        providing=zope.interface.Interface, layer='default'):
@@ -200,6 +204,7 @@
         self._skins = {'default': [self._layers['default']]}
         self.skins = {'default': ('default', )}
         self.defaultSkin = 'default'
+        self._usages = {'default': GlobalUsage(self, 'default')}
 
     def defineSkin(self, name, layers):
         """Define a skin
@@ -251,6 +256,13 @@
     def queryLayer(self, name):
         return self._layers.get(name)
 
+    def queryUsage(self, name):
+        return self._usages.get(name)
+
+    def useUsage(self, name):
+        if name and not self.queryUsage(name):
+            raise ValueError, ('Undefined usage', name)
+    
     def setDefaultSkin(self, name):
         """Set the default skin for a request type
 
@@ -299,6 +311,25 @@
 
         self._layers[name] = GlobalLayer(self, name)
 
+    def defineUsage(self, name):
+        """
+        >>> s = GlobalPresentationService()
+        >>> s.defineUsage('custom')
+       
+        You cannot redefine a usage:
+        
+        >>> s.defineUsage('custom')
+        Traceback (most recent call last):
+        ...
+        ValueError: ("Can't redefine usage", 'custom')
+        """
+        if name in self._usages:
+            raise ValueError("Can\'t redefine usage", name)
+
+        self._usages[name] = GlobalUsage(self, name)
+
+
+    
     def provideAdapter(self, request_type, factories, name=u'', contexts=(), 
                        providing=zope.interface.Interface, layer='default'):
         """Provide a presentation adapter
@@ -422,6 +453,9 @@
 def GL(presentation_service, layer_name):
     return presentation_service.queryLayer(layer_name)
 
+def GU(presentation_service, usage_name):
+    return presentation_service.queryUsage(usage_name)
+
 class GlobalLayer(zope.interface.surrogate.SurrogateRegistry):
 
     def __init__(self, parent, name):
@@ -431,3 +465,14 @@
 
     def __reduce__(self):
         return GL, (self.__parent__, self.__name__)
+
+
+class GlobalUsage(zope.interface.surrogate.SurrogateRegistry):
+
+    def __init__(self, parent, name):
+        zope.interface.surrogate.SurrogateRegistry.__init__(self)
+        self.__parent__ = parent
+        self.__name__ = name
+
+    def __reduce__(self):
+        return GU, (self.__parent__, self.__name__)




More information about the Zope3-Checkins mailing list