Author: jmorliaguet
Date: Thu Nov 10 16:14:54 2005
New Revision: 29447

Modified:
   
z3lab/cpsskins/branches/jmo-perspectives/browser/editing/presentation_editor.pt
   z3lab/cpsskins/branches/jmo-perspectives/configuration/interfaces.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py
   z3lab/cpsskins/branches/jmo-perspectives/perspectives/interfaces.py
Log:

- simpler model for registering resources:

  the resource gets embedded in the configuration item that is registered as
  as utility, so we can do:

  >>> item = queryUtility(configuration.ISomeItem)
  >>> resource = IResource(item).getResource()

  and use the resource in the application




Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/editing/presentation_editor.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/editing/presentation_editor.pt 
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/editing/presentation_editor.pt 
    Thu Nov 10 16:14:54 2005
@@ -32,13 +32,13 @@
                             display info/display;
                             formats info/formats;
                             perspective info/perspective;
-                            perspective_name perspective/name|nothing;
+                            perspective_name python: perspective and 
perspective.name or '';
                             perspective_is_current python: perspective == 
current_perspective;
                             current_formats python: current_perspective and 
                                             
views[current_perspective.name]['formats'] or []"
                 tal:attributes="class python: even and 'even' or nothing">
 
-              <td tal:content="view" />
+              <td tal:content="perspective/title|string:default" />
 
               <!-- Display -->
               <td>
@@ -54,7 +54,7 @@
                     <img src="/++skin++cpsskins/@@/remove-16.png" />
                   </a>
                 </tal:block>
-                <tal:block condition="python: not perspective">
+                <tal:block condition="not:perspective">
                   <img src="/++skin++cpsskins/@@/checked-disabled-16.png" />
                 </tal:block>
               </td>

Modified: z3lab/cpsskins/branches/jmo-perspectives/configuration/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/configuration/interfaces.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/configuration/interfaces.py        
Thu Nov 10 16:14:54 2005
@@ -19,6 +19,8 @@
 
 from zope.app.interface import Interface
 
+from cpsskins import interfaces
+
 class IRegistry(Interface):
     """Configuration registry
 
@@ -31,3 +33,7 @@
     def unregister(name):
        """Unregister an entry by its name"""
 
+class IResource(Interface):
+
+    def getResource():
+        """Return the resource."""

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
  (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
  Thu Nov 10 16:14:54 2005
@@ -17,7 +17,7 @@
   </content>
 
   <adapter
-      factory=".perspective.Element"
+      factory=".perspective.Resource"
   />
 
 </configure>

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
        (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
        Thu Nov 10 16:14:54 2005
@@ -21,6 +21,7 @@
 from zope.configuration.exceptions import ConfigurationError
 
 from cpsskins import configuration
+from cpsskins.perspectives import Perspective
 
 def perspective(_context, name=u'', title=u''):
 
@@ -28,5 +29,6 @@
         raise ConfigurationError(
             "The '%s' perspective has already been registered." % name)
 
-    provideUtility(configuration.Perspective(name=name, title=title),
+    resource = Perspective(name=name, title=title)
+    provideUtility(configuration.Perspective(resource=resource),
                    configuration.IPerspective, name)

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
  (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
  Thu Nov 10 16:14:54 2005
@@ -19,47 +19,35 @@
 __docformat__ = "reStructuredText"
 
 from zope.component import adapts
-from zope.interface import implements, Interface
+from zope.interface import implements, Interface, Attribute
 from zope.schema import DottedName, TextLine
 
 from cpsskins import interfaces
+from cpsskins.configuration.interfaces import IResource
 
 class IPerspective(Interface):
     """A perspective configuration item."""
 
-    name = DottedName(
-        title=u"Name",
-        )
-
-    title = TextLine(
-        title=u"Title",
-        )
+    resource = Attribute("The actual data.")
 
 class Perspective(object):
     """A perspective configuration item.
     """
     implements(IPerspective)
 
-    def __init__(self, name, title):
-        self.name = name 
-        self.title = title
+    def __init__(self, resource=None):
+        self.resource = resource
 
-class Element(object):
-    """This adapter turns perspective configuration items into elements that
+class Resource(object):
+    """This adapter turns perspective configuration items into resources that
     can natively be used by the application.
     """
     adapts(IPerspective)
-    implements(interfaces.IPerspective)
+    implements(IResource)
 
     def __init__(self, context):
         self.context = context
 
-    def name(self):
-        return self.context.name
+    def getResource(self):
+        return self.context.resource
 
-    def title(self):
-        return self.context.title
-
-    name = property(name)
-
-    title = property(title)

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py  (original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py  Thu Nov 10 
16:14:54 2005
@@ -23,6 +23,7 @@
 from zope.interface import implements
 
 from cpsskins import configuration
+from cpsskins.configuration.interfaces import IResource
 from cpsskins.elements.interfaces import IElement, INode, INodeTraverser
 from cpsskins.perspectives.interfaces import IPerspective
 from cpsskins.storage.interfaces import IPerspectiveStorage
@@ -87,7 +88,10 @@
 
     def getPerspectiveById(self, id):
         """Return a perspective by id."""
-        return IPerspective(queryUtility(configuration.IPerspective, id))
+        item = queryUtility(configuration.IPerspective, id)
+        if item is None:
+            return None
+        return IResource(item).getResource()
 
     def addPerspective(self, object):
         """Add a perspective to the perspective storage
@@ -99,8 +103,9 @@
 
     def listPerspectives(self):
         info = []
-        for name, object in getUtilitiesFor(configuration.IPerspective):
-            info.append({'name': object.name, 'title': object.title})
+        for name, item in getUtilitiesFor(configuration.IPerspective):
+            resource = IResource(item).getResource()
+            info.append({'name': resource.name, 'title': resource.title})
         return info
 
 class NodeTraverser(object):

Modified: z3lab/cpsskins/branches/jmo-perspectives/perspectives/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/perspectives/interfaces.py 
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/perspectives/interfaces.py Thu Nov 
10 16:14:54 2005
@@ -18,10 +18,19 @@
 __docformat__ = "reStructuredText"
 
 from zope.interface import Interface
+from zope.schema import DottedName, TextLine
 
 class IPerspective(Interface):
     """A perspective."""
 
+    name = DottedName(
+        title=u"Name",
+        )
+
+    title = TextLine(
+        title=u"Title",
+        )
+
     def __str__(self):
         """Return the name of the perspective"""
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to