Author: jmorliaguet
Date: Fri Jun 16 00:01:22 2006
New Revision: 3423

Modified:
   cpsskins/branches/paris-sprint-2006/browser/tree/slot.py
   cpsskins/branches/paris-sprint-2006/elements/display.py
   cpsskins/branches/paris-sprint-2006/standard/displays/boxgroup.py
   cpsskins/branches/paris-sprint-2006/standard/displays/configure.zcml

Log:

- the IGNORE_PERSPECTIVES / USE_PERSPECTIVE options are implemented using
  relations.



Modified: cpsskins/branches/paris-sprint-2006/browser/tree/slot.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/tree/slot.py    (original)
+++ cpsskins/branches/paris-sprint-2006/browser/tree/slot.py    Fri Jun 16 
00:01:22 2006
@@ -17,6 +17,7 @@
 """
 __docformat__ = "reStructuredText"
 
+import logging
 from zope.component import getMultiAdapter
 from zope.app.container.browser.adding import Adding
 from zope.publisher.browser import BrowserView
@@ -27,13 +28,14 @@
 from cpsskins.browser.tree.interfaces import INodeAdding, INodeRemoving
 from cpsskins.browser.tree.interfaces import INodeOrdering, INodeMoving
 from cpsskins.browser.tree.interfaces import INodeDuplicating, INodeTraversing
-from cpsskins.elements.display import IGNORE_PERSPECTIVES
-from cpsskins.elements.display import USE_CURRENT_PERSPECTIVE
 from cpsskins.elements.interfaces import IPortlet, IDisplayable, IFormattable
 from cpsskins.ontology import hasPortlet, hasPortletFromPerspective
+from cpsskins.ontology import hasPerspective
 from cpsskins.relations import DyadicRelation, TriadicRelation
 from cpsskins.utils import getThemeManager, getRelationStorage
 
+logger = logging.getLogger("cpsskins")
+
 class NodeTraversing(BrowserView):
     """This adapter makes slot nodes traversable.
     """
@@ -44,18 +46,34 @@
            Override this method if the element is a virtual container.
         """
         context = self.context
+        if display is None:
+            display = IDisplayable(context).getEffectiveDisplay(perspective)
+            logger.debug("Possible optimization: the display can be passed "
+                         "to slot.NodeTraversing.getChildNodes().")
+
         relations = getRelationStorage(context)
 
-        # TODO: refactor using relations
-        if perspective is None or display.mode == IGNORE_PERSPECTIVES:
+        # See if the display has a perspective explicitly associated.
+        # In that case it will override the perspective specified as a
+        # parameter.
+        display_perspective = relations.getSeconds(predicate=hasPerspective,
+                                                   first=display)
+        if len(display_perspective) >= 1:
+            perspective = display_perspective[0]
+
+            # If the associated perspective is represented by '*' then
+            # perspectives are ignored alltogether.
+            if str(perspective) == u'*':
+                perspective = None
+
+        if perspective is None:
             portlets = relations.getSeconds(predicate=hasPortlet, 
first=context)
-        elif display.mode == USE_CURRENT_PERSPECTIVE:
+        else:
             portlets = 
relations.getSeconds(predicate=hasPortletFromPerspective,
-                                          first=context, third=perspective)
+                                            first=context, third=perspective)
 
-        display = IDisplayable(context).getEffectiveDisplay(perspective)
         order = IFormattable(display).getFormat(u'order')
-
+        # TODO: optimize
         if order is not None:
             def cmp_by_order(a, b):
                 index = order.index

Modified: cpsskins/branches/paris-sprint-2006/elements/display.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/elements/display.py     (original)
+++ cpsskins/branches/paris-sprint-2006/elements/display.py     Fri Jun 16 
00:01:22 2006
@@ -31,9 +31,6 @@
 from cpsskins.storage.displays import IDisplayStorage
 from cpsskins.utils import getThemeManager, getRelationStorage, cloneObject
 
-USE_CURRENT_PERSPECTIVE = 1
-IGNORE_PERSPECTIVES = 2
-
 class Display(Element):
 
     implements(IDisplay)

Modified: cpsskins/branches/paris-sprint-2006/standard/displays/boxgroup.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/displays/boxgroup.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/displays/boxgroup.py   Fri Jun 
16 00:01:22 2006
@@ -19,28 +19,17 @@
 
 import logging
 from persistent import Persistent
-from persistent.list import PersistentList
-from zope.interface import implements, alsoProvides
+from zope.interface import implements
 from zope.i18nmessageid import MessageFactory
-from zope.schema import Choice
-from zope.schema.interfaces import IVocabularyFactory
-from zope.schema.vocabulary import SimpleVocabulary
 
 from cpsskins.elements.display import Display
-from cpsskins.elements.display import IGNORE_PERSPECTIVES
-from cpsskins.elements.display import USE_CURRENT_PERSPECTIVE
 from cpsskins.elements.interfaces import IDisplay
 
 _ = MessageFactory("cpsskins")
 logger = logging.getLogger("cpsskins")
 
 class IBoxGroup(IDisplay):
-
-    mode = Choice(
-        title=_(u"Display mode"),
-        description=_(u"The mode in which items are displayed"),
-        vocabulary="Display Modes",
-        required=True)
+    """ """
 
 class BoxGroup(Persistent, Display):
     """A Box Group is used to display a group of portlets.
@@ -49,21 +38,8 @@
 
     def __init__(self, **kw):
         super(BoxGroup, self).__init__(**kw)
-        self.mode = USE_CURRENT_PERSPECTIVE
 
     def __repr__(self):
         return "<BoxGroup: %s>" % self.identifier
 
-# List of display modes
-
-def DisplayModes(context):
-    """A vocabulary that contains the list of display modes
-    """
-    modes = [
-        (_(u"Use current perspective"), USE_CURRENT_PERSPECTIVE),
-        (_(u"Ignore perspectives"), IGNORE_PERSPECTIVES),
-    ]
-    return SimpleVocabulary.fromItems(modes)
-
-alsoProvides(DisplayModes, IVocabularyFactory)
 

Modified: cpsskins/branches/paris-sprint-2006/standard/displays/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/displays/configure.zcml        
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/displays/configure.zcml        
Fri Jun 16 00:01:22 2006
@@ -29,10 +29,4 @@
       class=".boxgroup.BoxGroup"
   />
 
-  <utility 
-     provides="zope.schema.interfaces.IVocabularyFactory"
-     component=".boxgroup.DisplayModes"
-     name="Display Modes"
-  />
-
 </configure>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to