Author: jmorliaguet
Date: Tue Oct 25 00:04:55 2005
New Revision: 28588

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
   
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
   z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/configure.zcml
   z3lab/cpsskins/branches/jmo-perspectives/elements/displays/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/presentation.py
Log:

- moved getElementType(), getContentType() out of the Element class.

 (added a path adapter for 'contenttype' and 'elementtype' used in ZPT)



Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/edit_menu.pt     
Tue Oct 25 00:04:55 2005
@@ -28,7 +28,7 @@
         <a class="item" i18n:translate=""
            href="@@edit-menu.html?main_url=@@edit.html">
           <img src="" tal:attributes="src context/@@getIcon" />
-          <tal:block i18n:translate="" content="context/contenttype" />
+          <tal:block i18n:translate="" content="context/type:contenttype" />
         </a>
       </li>
 
@@ -39,7 +39,7 @@
             tal:repeat="format formats">
           <a class="item format" i18n:translate=""
              tal:attributes="href 
string:./@@edit-menu.html?format=${format/formatname}"
-             tal:content="format/contenttype" />
+             tal:content="format/type:contenttype" />
         </li>
       </tal:block>
 

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
  (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/content/portlet_edit.pt
  Tue Oct 25 00:04:55 2005
@@ -7,7 +7,7 @@
     getDisplay nocall:context/displayable:getDisplay;
     actual_display python: getDisplay(perspective);
     formats actual_display/formattable:getFormatNames|python:[];
-    parent_type parent/elementtype;
+    parent_type parent/type:elementtype;
     editable python: str(parent_type) == 'ISlot' and 1 or 0;
     title context/title;
     id view/getId;"

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
     (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/authoring/filters/page/portlet_edit.pt
     Tue Oct 25 00:04:55 2005
@@ -17,7 +17,7 @@
     <div class="portletBoxLayoutMode" tal:condition="mode_is_layout">
       <strong tal:condition="title" tal:content="title" />
       (<tal:block i18n:domain="cpsskins"
-        i18n:translate="" content="context/contenttype" />)
+        i18n:translate="" content="context/type:contenttype" />)
     </div>
 
     <div

Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
Tue Oct 25 00:04:55 2005
@@ -30,6 +30,7 @@
 from cpsskins.browser.rendering.interfaces import IDisplayData, IUpdateData
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements.interfaces import IElement, ILeaf, ISlot, IDisplayable
+from cpsskins.elements.interfaces import IType
 from cpsskins.relations.interfaces import IPredicate
 from cpsskins.storage.interfaces import IRelationStorage
 from interfaces import IViewer, IRenderer, IFilter, IContextInfo
@@ -225,10 +226,10 @@
         rendered = ''.join(rendered)
 
         # look for renderers associated to the element's content type
-        iface = element.getContentType()
+        iface = IType(element).getContentType()
         if (iface, engine) not in renderer_registry:
             # fall back to the element type
-            iface = element.getElementType()
+            iface = IType(element).getElementType()
 
         if (iface, engine) not in renderer_registry:
             logger.log(INFO,

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/__init__.py       
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/__init__.py       Tue Oct 
25 00:04:55 2005
@@ -24,13 +24,13 @@
 from zope.app.container.interfaces import INameChooser
 from zope.app.content.interfaces import IContentType
 from zope.app.interface import queryType
+from zope.app.traversing.interfaces import IPathAdapter
 from zope.component import adapts
 from zope.interface import implements
 from zope.app.content.interfaces import IContentType
 
-from interfaces import (
-    IElement, IElementType, INode, IInnerNode, ILeaf, INodeTraverser
-    )
+from interfaces import IElement, IElementType, IType
+from interfaces import INode, IInnerNode, ILeaf, INodeTraverser
 
 class Element(Contained):
     """An element
@@ -43,20 +43,6 @@
         id = getattr(self, 'identifier', '')
         return str(id)
 
-    def getElementType(self):
-        return queryType(self, IElementType)
-
-    def getContentType(self):
-        return queryType(self, IContentType)
-
-    def _getElementTypeName(self):
-        return self.getElementType().__name__
-
-    def _getContentTypeName(self):
-        return self.getContentType().__name__
-
-    contenttype = property(_getContentTypeName)
-    elementtype = property(_getElementTypeName)
 
 class Node(Element):
     """A Node is an element in a tree structure.
@@ -109,3 +95,39 @@
 
     __used_for__ = IElement
 
+
+class ElementType(object):
+    """Adapter that gets the element type of an element.
+    """
+    adapts(IElement)
+    implements(IElementType)
+
+    def __init__(self, element):
+        self.element = element
+
+    def __call__(self):
+        return queryType(self.element, IElementType)
+
+    def __str__(self):
+        return str(self())
+
+class Type(object):
+    """Adapter that gets the content type of an element.
+    """
+    adapts(IElement)
+    implements(IType, IPathAdapter)
+
+    def __init__(self, element):
+        self.element = element
+
+    def getContentType(self):
+        return queryType(self.element, IContentType)
+
+    def getElementType(self):
+        return queryType(self.element, IElementType)
+
+    def contenttype(self):
+        return self.getContentType().__name__
+
+    def elementtype(self):
+        return self.getElementType().__name__

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/configure.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/configure.zcml    
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/configure.zcml    Tue Oct 
25 00:04:55 2005
@@ -13,6 +13,21 @@
       provides="zope.app.container.interfaces.INameChooser"
   />
 
+  <!-- this adapter make it possible to get the types of an element -->
+
+  <adapter
+      for=".interfaces.IElement"
+      factory=".Type"
+      provides=".interfaces.IType"
+  />
+
+  <adapter
+      name="type"
+      provides="zope.app.traversing.interfaces.IPathAdapter"
+      for=".interfaces.IElement"
+      factory=".Type"
+  />
+
   <!-- these adapters make nodes traversable -->
 
   <adapter

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      
Tue Oct 25 00:04:55 2005
@@ -27,7 +27,7 @@
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements import Element
 from cpsskins.elements.interfaces import IDisplayable, IDisplay, IDisplayType
-from cpsskins.elements.interfaces import IFormattable
+from cpsskins.elements.interfaces import IType, IFormattable
 from cpsskins.perspectives.interfaces import IPerspective
 from cpsskins.relations import DyadicRelation, TriadicRelation
 from cpsskins.relations.tool import RelationTool
@@ -217,9 +217,12 @@
         """
         context = self.context
 
-        presentation = presentation_registry.get(context.getContentType())
+        content_type = IType(context).getContentType()
+        element_type = IType(context).getElementType()
+
+        presentation = presentation_registry.get(content_type)
         if presentation is None:
-            presentation = presentation_registry.get(context.getElementType())
+            presentation = presentation_registry.get(element_type)
 
         display_name = presentation['display']
         display_factory = display_registry[display_name]['factory']

Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py       
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/elements/formats/__init__.py       
Tue Oct 25 00:04:55 2005
@@ -26,7 +26,7 @@
 
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements import Element
-from cpsskins.elements.interfaces import IFormat, IFormattable
+from cpsskins.elements.interfaces import IType, IFormat, IFormattable
 from cpsskins.ontology import hasFormat
 from cpsskins.relations import DyadicRelation
 from cpsskins.relations.tool import RelationTool
@@ -43,7 +43,7 @@
         self.id = id
 
     def _getFormatName(self):
-        return self.getContentType().getTaggedValue('name')
+        return IType(self).getContentType().getTaggedValue('name')
 
     def findDisplays(self):
         """Return the list of display elements associated to this

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     Tue Oct 
25 00:04:55 2005
@@ -33,14 +33,10 @@
 
     identifier = Attribute("Identifier")
 
-    elementtype = Attribute("Element type")
-
-    contenttype = Attribute("Content type")
-
     def __str__():
         """The string representation is used as an identifier in a relation."""
 
-    # this will go away
+class IType(Interface):
 
     def getContentType():
         """ """
@@ -48,6 +44,12 @@
     def getElementType():
         """ """
 
+    def contenttype():
+        """ """
+
+    def elementtype():
+        """ """
+
 class INode(IElement):
     """A generic tree node"""
 

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   Tue Oct 
25 00:04:55 2005
@@ -22,7 +22,7 @@
 from zope.component import getUtility
 
 from cpsskins.configuration.interfaces import IRegistry
-from cpsskins.elements.interfaces import IDisplayable, IFormattable
+from cpsskins.elements.interfaces import IType, IDisplayable, IFormattable
 from cpsskins.ontology import hasFormat, hasDisplay, hasDisplayFromPerspective
 from cpsskins.relations.tool import RelationTool
 from cpsskins.thememanager import getThemeManager
@@ -59,9 +59,13 @@
         display = displayable.addDisplay(perspective)
 
         formattable = IFormattable(display)
-        factory_info = presentation_registry.get(context.getContentType())
+
+        content_type = IType(context).getContentType()
+        element_type = IType(context).getElementType()
+
+        factory_info = presentation_registry.get(content_type)
         if factory_info is None:
-            factory_info = presentation_registry.get(context.getElementType())
+            factory_info = presentation_registry.get(element_type)
         for type, id in factory_info['formats'].items():
             formattable.addFormat(type, id)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to