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

Godefroid Chapelle cvs-admin at zope.org
Sun Dec 7 05:04:55 EST 2003


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

Modified Files:
	presentation.py 
Log Message:
merge gotcha-usage-branch

this finishes support for usage :

top-level variable in page templates
initialized from ZCML

main goal is to use a unique template per skin

now, I should walk all templates that relies on dialog_macros.pt
and convert them to template.pt 




=== Zope3/src/zope/component/presentation.py 1.2 => 1.3 ===
--- Zope3/src/zope/component/presentation.py:1.2	Fri Nov 21 12:09:26 2003
+++ Zope3/src/zope/component/presentation.py	Sun Dec  7 05:04:54 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