Author: jmorliaguet
Date: Fri Nov  4 22:48:02 2005
New Revision: 29005

Modified:
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/__init__.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/meta.zcml
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/metaconfigure.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/display.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/presentation.py
Log:

- converted the presentation registry into a utility



Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/__init__.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/__init__.py
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/__init__.py
    Fri Nov  4 22:48:02 2005
@@ -17,9 +17,3 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.component import provideUtility
-
-from cpsskins.configuration import ConfigurationRegistry
-from cpsskins.configuration.interfaces import IRegistry
-
-provideUtility(ConfigurationRegistry(), IRegistry, 'presentations')

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/meta.zcml
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/meta.zcml  
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/meta.zcml  
    Fri Nov  4 22:48:02 2005
@@ -6,7 +6,7 @@
     <complexDirective
         name="presentation"
         schema=".metadirectives.IPresentationDirective"
-        handler=".metaconfigure.Presentation">
+        handler=".metaconfigure.PresentationDirective">
 
       <subdirective
           name="display"

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/metaconfigure.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/metaconfigure.py
       (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/metaconfigure.py
       Fri Nov  4 22:48:02 2005
@@ -17,17 +17,16 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.component import getUtility
+from zope.component import getUtility, provideUtility
 from zope.configuration.exceptions import ConfigurationError
 from zope.i18nmessageid import MessageFactory
 
-from cpsskins.configuration.interfaces import IRegistry
+from cpsskins.elements.presentation import Presentation
+from cpsskins.elements.interfaces import IPresentation
 
 _ = MessageFactory("cpsskins")
 
-presentation_registry = getUtility(IRegistry, 'presentations')
-
-class Presentation(object):
+class PresentationDirective(object):
 
     def __init__(self, _context, for_):
         self._context = _context
@@ -46,6 +45,7 @@
         if not self._display:
             raise ConfigurationError("Must specify a display type.")
 
-        presentation_registry.register(self.for_,
-            {'display': self._display, 'formats': self._formats})
+        provideUtility(
+            Presentation(display=self._display, formats=self._formats),
+            IPresentation, self.for_.__name__)
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/display.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/display.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/display.py        Fri Nov 
 4 22:48:02 2005
@@ -17,13 +17,16 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.app import zapi
 from zope.app.interface import queryType
 from zope.app.location.pickling import locationCopy
 from zope.app.traversing.interfaces import IPathAdapter
-from zope.component import getUtility
+from zope.component import getUtility, queryUtility
 from zope.interface import implements
 from zope.security.proxy import removeSecurityProxy
 
+from cpsskins.elements.interfaces import IPresentation
+
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements import Element
 from cpsskins.elements.interfaces import IType
@@ -36,7 +39,6 @@
 from interfaces import IDisplayable, IDisplay, IDisplayType
 
 display_registry = getUtility(IRegistry, 'displays')
-presentation_registry = getUtility(IRegistry, 'presentations')
 
 class Display(Element):
 
@@ -217,14 +219,12 @@
         """
         context = self.context
 
-        content_type = IType(context).getContentType()
-        element_type = IType(context).getElementType()
-
-        presentation = presentation_registry.get(content_type)
+        type = IType(context)
+        presentation = queryUtility(IPresentation, type.contenttype())
         if presentation is None:
-            presentation = presentation_registry.get(element_type)
+            presentation = queryUtility(IPresentation, type.elementtype())
 
-        display_name = presentation['display']
+        display_name = presentation.display
         display_factory = display_registry[display_name]['factory']
         return apply(display_factory, ())
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py     Fri Nov 
 4 22:48:02 2005
@@ -137,6 +137,9 @@
     def storeFormat(format):
         """Add a format to the format storage."""
 
+class IPresentation(Interface):
+    """A Presentation."""
+
 class IPresentable(Interface):
     """Presentable elements can be displayed and formatted."""
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/presentation.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/presentation.py   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/presentation.py   Fri Nov 
 4 22:48:02 2005
@@ -19,17 +19,24 @@
 
 from zope.app.traversing.interfaces import IPathAdapter
 from zope.interface import implements
-from zope.component import getUtility
+from zope.component import getUtility, queryUtility
 
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements.interfaces import IType, IDisplayable, IFormattable
+from cpsskins.elements.interfaces import IPresentation
 from cpsskins.ontology import hasFormat, hasDisplay, hasDisplayFromPerspective
 from cpsskins.relations.tool import RelationTool
 from cpsskins.thememanager import getThemeManager
 from interfaces import IPresentable
 
-format_registry = getUtility(IRegistry, 'formats')
-presentation_registry = getUtility(IRegistry, 'presentations')
+
+class Presentation(object):
+
+    implements(IPresentation)
+
+    def __init__(self, display=None, formats=[]):
+        self.display = display
+        self.formats = formats
 
 class Presentable(object):
     """This adapter makes elements presentable, i.e. displayable and 
formattable
@@ -60,13 +67,12 @@
 
         formattable = IFormattable(display)
 
-        content_type = IType(context).getContentType()
-        element_type = IType(context).getElementType()
+        type = IType(context)
 
-        factory_info = presentation_registry.get(content_type)
+        factory_info = queryUtility(IPresentation, type.contenttype())
         if factory_info is None:
-            factory_info = presentation_registry.get(element_type)
-        for type, id in factory_info['formats'].items():
+            factory_info = queryUtility(IPresentation, type.elementtype())
+        for type, id in factory_info.formats.items():
             formattable.addFormat(type, id)
 
     def clonePresentation(self, perspective=None):
@@ -116,6 +122,7 @@
         current_format = formattable.getFormat(name)
         format = formattable.cloneFormat(current_format)
 
+        format_registry = getUtility(IRegistry, 'formats')
         predicate = format_registry.get(name)['predicate']
         relations = reltool.search(first=display, predicate=predicate)
         reltool.remove(relations)
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to