Author: jmorliaguet
Date: Sat Oct 22 13:01:16 2005
New Revision: 28529

Added:
   z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/
   z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/__init__.py  
 (contents, props changed)
   z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/meta.zcml   
(contents, props changed)
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metaconfigure.py
   (contents, props changed)
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metadirectives.py
   (contents, props changed)
Removed:
   z3lab/cpsskins/branches/jmo-perspectives/configuration/elements/
Modified:
   z3lab/cpsskins/branches/jmo-perspectives/configuration/meta.zcml
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/presentations/metaconfigure.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/displays/configure.zcml
Log:

- display elements are registered using zcml



Added: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/__init__.py
==============================================================================
--- (empty file)
+++ z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/__init__.py 
Sat Oct 22 13:01:16 2005
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.component import provideUtility
+from zope.interface import implements
+
+from cpsskins.configuration import ConfigurationRegistry
+from cpsskins.configuration.interfaces import IRegistry
+
+class DisplayRegistry(ConfigurationRegistry):
+    """A format registry stores information about displays
+    """
+    implements(IRegistry)
+
+provideUtility(DisplayRegistry(), IRegistry, 'displays')
+

Added: z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/meta.zcml
==============================================================================
--- (empty file)
+++ z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/meta.zcml   
Sat Oct 22 13:01:16 2005
@@ -0,0 +1,14 @@
+
+
+<configure xmlns="http://namespaces.zope.org/meta";>
+
+  <directives namespace="http://namespaces.zope.org/cpsskins";>
+
+    <directive
+       name="display"
+       schema=".metadirectives.IDisplayDirective"
+       handler=".metaconfigure.display" />
+
+  </directives>
+
+</configure>

Added: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metaconfigure.py
==============================================================================
--- (empty file)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metaconfigure.py
    Sat Oct 22 13:01:16 2005
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import os
+
+from zope.app.annotation.interfaces import IAttributeAnnotatable
+from zope.app.component.contentdirective import ContentDirective
+from zope.app.component.metaconfigure import adapter
+from zope.app.content.interfaces import IContentType
+from zope.app.form.browser.metaconfigure import EditFormDirective
+from zope.configuration.exceptions import ConfigurationError
+from zope.component import getUtility
+from zope.interface import alsoProvides
+
+from cpsskins.configuration.interfaces import IRegistry
+from cpsskins.elements.interfaces import IDisplay, IElementType, IDisplayType
+
+display_registry = getUtility(IRegistry, 'displays')
+
+def display(_context, name='', schema=None, factory=None):
+
+    if not name:
+        raise ConfigurationError("Must specify the display name.")
+
+    if not name.isalpha():
+        raise ConfigurationError(
+            "Display names can only contain alphabetic characters.")
+
+    if name in display_registry:
+        raise ConfigurationError, \
+            "A display with the name '%s' has already been registered." % name
+
+    if not schema:
+        raise ConfigurationError, \
+            "Must specify the display schema."
+
+    if not factory:
+        raise ConfigurationError("Must specify a display factory.")
+
+    # zope:content
+    c = ContentDirective(_context=_context, class_=factory)
+    c.implements(_context=_context,interface=(IAttributeAnnotatable,))
+    c.require(_context=_context,
+        permission="zope.View",
+        interface=(schema,))
+    c.require(_context=_context,
+        permission="zope.ManageContent",
+        set_schema=(schema,))
+
+    # zope:adapter
+    adapter(_context=_context,
+        factory=(factory,),
+        provides=schema,
+        for_=(IDisplay,),
+        name=name,
+        )
+
+    # register the display
+    display_registry.register(name, {'factory': factory})
+
+    # set up interface types
+    alsoProvides(IDisplay, IElementType)
+    alsoProvides(schema, IContentType)
+    alsoProvides(schema, IDisplayType)
+
+    schema.setTaggedValue('name', name)
+

Added: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metadirectives.py
==============================================================================
--- (empty file)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/displays/metadirectives.py
   Sat Oct 22 13:01:16 2005
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docdisplay__ = "reStructuredText"
+
+from zope.configuration.fields import GlobalObject, Path, GlobalInterface
+from zope.interface import Interface
+from zope.i18nmessageid import MessageFactory
+from zope.schema import TextLine
+
+_ = MessageFactory("cpsskins")
+
+class IDisplayDirective(Interface):
+
+    name = TextLine(
+        title=_("Name"),
+        description=_("The display's name"),
+        required=False,
+        default=u'',
+       )
+
+    schema = GlobalInterface(
+        title=_("Schema"),
+        description=_("The display's schema"),
+        required=False,
+        )
+
+    factory = GlobalObject(
+        title=_("Factory"),
+        description=_("The display's factory."),
+        required=False,
+        )

Modified: z3lab/cpsskins/branches/jmo-perspectives/configuration/meta.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/configuration/meta.zcml    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/configuration/meta.zcml    Sat Oct 
22 13:01:16 2005
@@ -10,11 +10,12 @@
 
   <include package=".presentations" file="meta.zcml" />
 
-  <include package=".storages" file="meta.zcml" />
+  <include package=".displays" file="meta.zcml" />
 
   <include package=".formats" file="meta.zcml" />
 
   <include package=".widgets" file="meta.zcml" />
 
+  <include package=".storages" file="meta.zcml" />
 
 </configure>

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
       Sat Oct 22 13:01:16 2005
@@ -46,6 +46,10 @@
         self._formats[name] = id
 
     def __call__(self):
+
+        if not self._display:
+            raise ConfigurationError("Must specify a display type.")
+
         presentation_registry.register(self.for_,
             {'display': self._display, 'formats': self._formats})
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py      
Sat Oct 22 13:01:16 2005
@@ -35,6 +35,7 @@
 from cpsskins.thememanager import getThemeManager
 from cpsskins.storage.interfaces import IDisplayStorage
 
+display_registry = getUtility(IRegistry, 'displays')
 presentation_registry = getUtility(IRegistry, 'presentations')
 
 class Display(Element):
@@ -214,12 +215,13 @@
     def factory(self):
         """Display factory. Return a display element.
         """
-        from cpsskins.configuration.elements import display_factories
         context = self.context
-        factory_info = presentation_registry.get(context.getContentType())
-        if factory_info is None:
-            factory_info = presentation_registry.get(context.getElementType())
-        display_name = factory_info['display']
-        factory = display_factories[display_name]
-        return apply(factory, ())
+
+        presentation = presentation_registry.get(context.getContentType())
+        if presentation is None:
+            presentation = presentation_registry.get(context.getElementType())
+
+        display_name = presentation['display']
+        display_factory = display_registry[display_name]['factory']
+        return apply(display_factory, ())
 

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/elements/displays/configure.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/displays/configure.zcml   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/displays/configure.zcml   
Sat Oct 22 13:01:16 2005
@@ -1,5 +1,6 @@
 <configure
     xmlns="http://namespaces.zope.org/zope";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";
     xmlns:i18n="http://namespaces.zope.org/i18n";
     i18n_domain="cpsskins"
     >
@@ -29,74 +30,28 @@
 
   <!-- Area display -->
 
-  <interface
-      interface=".interfaces.IArea"
-      type="..interfaces.IDisplayType"
-  />
-
-  <adapter
+  <cpsskins:display
       name="area"
-      provides=".interfaces.IArea"
-      for="..interfaces.IDisplay"
+      schema=".interfaces.IArea"
       factory=".area.Area"
   />
 
-  <content class=".area.Area">
-
-    <require
-        permission="zope.View"
-        interface=".interfaces.IArea"
-        />
-
-    <require
-        permission="zope.ManageContent"
-        set_schema=".interfaces.IArea"
-        />
-
-  </content>
-
-
   <!-- Box display -->
 
-  <interface
-      interface=".interfaces.IBox"
-      type="..interfaces.IDisplayType"
+  <cpsskins:display
+      name="box"
+      schema=".interfaces.IBox"
+      factory=".box.Box"
   />
 
-  <content class=".box.Box">
-
-    <require
-        permission="zope.View"
-        interface=".interfaces.IBox"
-        />
-
-    <require
-        permission="zope.ManageContent"
-        set_schema=".interfaces.IBox"
-        />
-
-  </content>
-
 
   <!-- Box group display -->
 
-  <interface
-      interface=".interfaces.IBoxGroup"
-      type="..interfaces.IDisplayType"
+  <cpsskins:display
+      name="boxgroup"
+      schema=".interfaces.IBoxGroup"
+      factory=".boxgroup.BoxGroup"
   />
 
-  <content class=".boxgroup.BoxGroup">
-
-    <require
-        permission="zope.View"
-        interface=".interfaces.IBoxGroup"
-        />
-
-    <require
-        permission="zope.ManageContent"
-        set_schema=".interfaces.IBoxGroup"
-        />
-
-  </content>
 
 </configure>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to