Author: jmorliaguet
Date: Sat Nov 26 16:15:33 2005
New Revision: 1935

Modified:
   cpsskins/branches/jmo-perspectives/controllers/theme.py
   cpsskins/branches/jmo-perspectives/elements/cell.py
   cpsskins/branches/jmo-perspectives/elements/element.py
   cpsskins/branches/jmo-perspectives/elements/interfaces.py
   cpsskins/branches/jmo-perspectives/elements/pageblock.py
   cpsskins/branches/jmo-perspectives/elements/presentation.py
   cpsskins/branches/jmo-perspectives/elements/slot.py
   cpsskins/branches/jmo-perspectives/elements/theme.py
   cpsskins/branches/jmo-perspectives/elements/themepage.py
   cpsskins/branches/jmo-perspectives/engines/authoring/authoring_macros.pt
   cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
   cpsskins/branches/jmo-perspectives/interfaces.py
   cpsskins/branches/jmo-perspectives/relations/storage.py
   cpsskins/branches/jmo-perspectives/thememanager.py
Log:

- moved methods from element.theme to the theme manager

- using super() in constructors

- fixes




Modified: cpsskins/branches/jmo-perspectives/controllers/theme.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/controllers/theme.py     (original)
+++ cpsskins/branches/jmo-perspectives/controllers/theme.py     Sat Nov 26 
16:15:33 2005
@@ -38,4 +38,4 @@
             tmutil.setAsDefault(element)
 
         # XXX for testing
-       element.addPerspective(name=u'local', title=u'Local perspective')
+        tmutil.addPerspective(name=u'local', title=u'Local perspective')

Modified: cpsskins/branches/jmo-perspectives/elements/cell.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/cell.py (original)
+++ cpsskins/branches/jmo-perspectives/elements/cell.py Sat Nov 26 16:15:33 2005
@@ -32,8 +32,8 @@
     """
     implements(ICell)
 
-    def __init__(self, title=''):
-        InnerNode.__init__(self)
+    def __init__(self, title=u''):
+        super(Cell, self).__init__()
         self.title = title
 
     def __repr__(self):

Modified: cpsskins/branches/jmo-perspectives/elements/element.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/element.py      (original)
+++ cpsskins/branches/jmo-perspectives/elements/element.py      Sat Nov 26 
16:15:33 2005
@@ -48,7 +48,7 @@
         self.element = element
 
     def __str__(self):
-        id = getattr(self.element, 'identifier', '')
+        id = getattr(self.element, 'identifier', u'')
         return str(id)
 
 class Node(Element):
@@ -57,7 +57,7 @@
     implements(INode)
 
     def __init__(self):
-        Element.__init__(self)
+        super(Node, self)._init__()
 
 class InnerNode(OrderedContainer, Node):
     """An inner node is a node that has children.
@@ -65,8 +65,7 @@
     implements(IInnerNode)
 
     def __init__(self):
-        Node.__init__(self)
-        OrderedContainer.__init__(self)
+        super(InnerNode, self).__init__()
 
 class Leaf(Persistent, Node):
     """A leaf is a node that has no children.
@@ -74,7 +73,7 @@
     implements(ILeaf)
 
     def __init__(self):
-        Node.__init__(self)
+        super(Leaf, self).__init__()
 
 class NodeTraverser(object):
     """An adapter for traversing the tree.

Modified: cpsskins/branches/jmo-perspectives/elements/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/interfaces.py   (original)
+++ cpsskins/branches/jmo-perspectives/elements/interfaces.py   Sat Nov 26 
16:15:33 2005
@@ -240,17 +240,6 @@
         """Set the theme as the default theme.
         """
 
-    def getPerspectiveByName(name):
-        """Return a perspective by name
-        """
-
-    def addPerspective(perspective, id):
-        """Add a perspective to the storage
-        """
-
-    def listPerspectives():
-        """ """
-
 # theme objects
 class IElementContainer(IOrderedContainer):
     pass

Modified: cpsskins/branches/jmo-perspectives/elements/pageblock.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/pageblock.py    (original)
+++ cpsskins/branches/jmo-perspectives/elements/pageblock.py    Sat Nov 26 
16:15:33 2005
@@ -32,8 +32,8 @@
     """
     implements(IPageBlock)
 
-    def __init__(self, title=''):
-        InnerNode.__init__(self)
+    def __init__(self, title=u''):
+        super(PageBlock, self).__init__()
         self.title = title
 
     def __repr__(self):

Modified: cpsskins/branches/jmo-perspectives/elements/presentation.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/presentation.py (original)
+++ cpsskins/branches/jmo-perspectives/elements/presentation.py Sat Nov 26 
16:15:33 2005
@@ -142,12 +142,9 @@
         reltool = RelationTool(object)
 
         tmutil = getThemeManager()
-        theme = tmutil.getThemeInContext(object)
-
         presentations = {}
-
         # set initial values
-        for perspective in theme.listPerspectives():
+        for perspective in tmutil.listPerspectives():
             presentation_id = perspective.name
             presentations[presentation_id] = {
                 'relation': None,

Modified: cpsskins/branches/jmo-perspectives/elements/slot.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/slot.py (original)
+++ cpsskins/branches/jmo-perspectives/elements/slot.py Sat Nov 26 16:15:33 2005
@@ -41,8 +41,8 @@
     """
     implements(ISlot)
 
-    def __init__(self, title='', _slot=''):
-        InnerNode.__init__(self)
+    def __init__(self, title=u'', _slot=u''):
+        super(Slot, self).__init__()
         self.title = title
         self._slot = _slot
 

Modified: cpsskins/branches/jmo-perspectives/elements/theme.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/theme.py        (original)
+++ cpsskins/branches/jmo-perspectives/elements/theme.py        Sat Nov 26 
16:15:33 2005
@@ -18,14 +18,12 @@
 __docformat__ = "reStructuredText"
 
 from zope.app.component.site import SiteManagementFolder
-from zope.component import adapts, getUtility
+from zope.component import adapts
 from zope.interface import implements
 
 from cpsskins.elements.interfaces import INode, INodeTraverser
 from cpsskins.elements.interfaces import ITheme, IThemePage
-from cpsskins.perspectives import Perspective
 from cpsskins.utils import getThemeManager
-from cpsskins.setup.interfaces import IResourceManager
 
 class Theme(SiteManagementFolder):
     """Theme
@@ -37,7 +35,7 @@
     """
     implements(ITheme)
 
-    def __init__(self, title=''):
+    def __init__(self, title=u''):
         super(Theme, self).__init__()
         self.title = title
 
@@ -64,8 +62,7 @@
         >>> theme.getPages() == [page]
         True
         """
-        return [v for v in self.values()
-               if IThemePage.providedBy(v)]
+        return [v for v in self.values() if IThemePage.providedBy(v)]
 
     def setAsDefault(self):
         return getThemeManager().setAsDefault(self)
@@ -73,20 +70,6 @@
     def isDefault(self):
         return getThemeManager().isDefault(self)
 
-    def getPerspectiveByName(self, name):
-        """Return a perspective by name."""
-        return getUtility(IResourceManager, 'perspectives').lookup(name, self)
-
-    def addPerspective(self, name, title):
-        """Add a perspective to the perspective storage.
-        """
-        perspective = Perspective(name=name, title=title)
-        mgr = getUtility(IResourceManager, 'perspectives')
-        mgr.register(title=title, resource=perspective, context=self)
-
-    def listPerspectives(self):
-        return getUtility(IResourceManager, 'perspectives').list(self)
-
 class NodeTraverser(object):
     """This adapter makes theme nodes traversable.
     """
@@ -101,3 +84,4 @@
         TODO: Return the effective page instead
         """
         return [self.node.getDefaultPage()]
+

Modified: cpsskins/branches/jmo-perspectives/elements/themepage.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/themepage.py    (original)
+++ cpsskins/branches/jmo-perspectives/elements/themepage.py    Sat Nov 26 
16:15:33 2005
@@ -28,13 +28,13 @@
     """
     implements(IThemePage)
 
-    def __init__(self, title=''):
+    def __init__(self, title=u''):
         """
         >>> page = ThemePage('Some theme page')
         >>> page
         ThemePage('Some theme page')
         """
-        InnerNode.__init__(self)
+        super(ThemePage, self).__init__()
         self.title = title
 
     def __repr__(self):

Modified: 
cpsskins/branches/jmo-perspectives/engines/authoring/authoring_macros.pt
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/authoring/authoring_macros.pt    
(original)
+++ cpsskins/branches/jmo-perspectives/engines/authoring/authoring_macros.pt    
Sat Nov 26 16:15:33 2005
@@ -45,7 +45,7 @@
 <metal:block define-macro="perspective_selector" i18n:domain="cpsskins">
   <form class="perspective" title="Perspective selector" 
i18n:attributes="title"
         action="@@setPerspective" method="post"
-        tal:define="perspectives current_theme/listPerspectives;
+        tal:define="perspectives tmutil/listPerspectives;
                     current context/@@getPerspective">
     <select onchange="submit()" name="perspective">
       <option value="" i18n:translate="">default</option>

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
Sat Nov 26 16:15:33 2005
@@ -74,7 +74,7 @@
 
     def traverse(self, name, remaining):
         if name in self._getAllowedKeys():
-            return str(self[name])
+            return str(self.get(name, ''))
         return getattr(self, name, None)
 
     def __setitem__(self, k, v):

Modified: cpsskins/branches/jmo-perspectives/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/interfaces.py    (original)
+++ cpsskins/branches/jmo-perspectives/interfaces.py    Sat Nov 26 16:15:33 2005
@@ -74,7 +74,6 @@
         A context must be provided with.
         """
 
-    # TODO: move somewhere else
     def removeDisplays(object):
         """Remove the display of an element
         """
@@ -83,6 +82,17 @@
         """Remove the display of an element
         """
 
+    def getPerspectiveByName(name):
+        """Return a perspective by name
+        """
+
+    def addPerspective(perspective, id):
+        """Add a perspective to the storage
+        """
+
+    def listPerspectives():
+        """ """
+
 class IImageCache(IRAMCache):
 
     def __getitem__(key):

Modified: cpsskins/branches/jmo-perspectives/relations/storage.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/relations/storage.py     (original)
+++ cpsskins/branches/jmo-perspectives/relations/storage.py     Sat Nov 26 
16:15:33 2005
@@ -211,7 +211,7 @@
     __btree__delitem__ = BTreeContainer.__delitem__
 
     def __init__(self, **kw):
-        BTreeContainer.__init__(self)
+        super(RelationStorage, self).__init__()
         self._relates = OOBTree()
 
     def __setitem__(self, key, object):

Modified: cpsskins/branches/jmo-perspectives/thememanager.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/thememanager.py  (original)
+++ cpsskins/branches/jmo-perspectives/thememanager.py  Sat Nov 26 16:15:33 2005
@@ -27,22 +27,23 @@
 from zope.interface import implements
 
 from cpsskins.caching import ImageCache
-from cpsskins.setup.interfaces import ISettings
-from cpsskins.setup.settings import Settings
-from cpsskins.interfaces import IThemeManagement, IImageCache
 from cpsskins.elements.interfaces import ITheme, IThemeContainer, IThemePage
 from cpsskins.elements.interfaces import IFormattable
+from cpsskins.engines.default.displays.interfaces import IDisplayStorage
+from cpsskins.engines.default.displays.storage import DisplayStorage
+from cpsskins.engines.default.formats.interfaces import IFormatStorage
+from cpsskins.engines.default.formats.storage import FormatStorage
+from cpsskins.interfaces import IThemeManagement, IImageCache
 from cpsskins.ontology import isDefault, hasFormat, hasDisplay
-from cpsskins.portlets.storage import PortletStorage
+from cpsskins.perspectives import Perspective
 from cpsskins.portlets.interfaces import IPortletStorage
+from cpsskins.portlets.storage import PortletStorage
 from cpsskins.relations import MonadicRelation
-from cpsskins.relations.tool import RelationTool
-from cpsskins.relations.storage import RelationStorage
 from cpsskins.relations.interfaces import IRelationStorage
-from cpsskins.engines.default.formats.storage import FormatStorage
-from cpsskins.engines.default.formats.interfaces import IFormatStorage
-from cpsskins.engines.default.displays.storage import DisplayStorage
-from cpsskins.engines.default.displays.interfaces import IDisplayStorage
+from cpsskins.relations.storage import RelationStorage
+from cpsskins.relations.tool import RelationTool
+from cpsskins.setup.interfaces import IResourceManager, ISettings
+from cpsskins.setup.settings import Settings
 
 def added(object, event):
     object.registerUtilities()
@@ -74,6 +75,10 @@
         self['displays'] = DisplayStorage()
         self['formats'] = FormatStorage()
 
+    ###################################################################
+    # Local utilities
+    ###################################################################
+
     def registerUtilities(self):
         self.registerUtility(IIntIds, self['uids'])
         self.registerUtility(IImageCache, self['imagecache'])
@@ -97,6 +102,10 @@
     def getRelationStorage(self):
         return getUtility(IRelationStorage, context=self)
 
+    ###################################################################
+    # Unique id registry
+    ###################################################################
+
     def registerElement(self, element):
         id = self.getIdRegistry().register(element)
         # store the element's id in the element itself.
@@ -109,6 +118,10 @@
         """Return the element by its id"""
         return self.getIdRegistry().getObject(int(id))
 
+    ###################################################################
+    # Themes and pages
+    ###################################################################
+
     def getThemes(self):
         """Return the list of themes
 
@@ -165,6 +178,8 @@
     def getThemeInContext(self, context=None):
         """Return the theme in a given context.
         """
+        if ITheme.providedBy(context):
+            return context
         return queryUtility(ITheme, context=context)
 
     def setAsDefault(self, object=None):
@@ -173,6 +188,10 @@
         relations = getUtility(IRelationStorage, context=object)
         relations.add(MonadicRelation(isDefault, object))
 
+    ###################################################################
+    # Displays
+    ###################################################################
+
     def removeDisplays(self, object):
         """Remove the displays of a given element
         """
@@ -188,6 +207,10 @@
         # Remove the relation
         reltool.remove(display_relations)
 
+    ###################################################################
+    # Formats
+    ###################################################################
+
     def removeFormats(self, object):
         """Remove the formats of a given element
         """
@@ -201,3 +224,21 @@
         relations = reltool.search(first=object, predicate=hasFormat)
         reltool.remove(relations)
 
+    ###################################################################
+    # Perspectives
+    ###################################################################
+
+    def listPerspectives(self):
+        return getUtility(IResourceManager, 'perspectives').list(self)
+
+    def getPerspectiveByName(self, name):
+        """Return a perspective by name."""
+        return getUtility(IResourceManager, 'perspectives').lookup(name, self)
+
+    def addPerspective(self, name, title):
+        """Add a perspective to the perspective storage.
+        """
+        perspective = Perspective(name=name, title=title)
+        mgr = getUtility(IResourceManager, 'perspectives')
+        mgr.register(title=title, resource=perspective, context=self)
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to