Author: jmorliaguet
Date: Tue Nov 22 15:01:03 2005
New Revision: 1921

Modified:
   cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
   cpsskins/branches/jmo-perspectives/browser/tree/slot.py
   cpsskins/branches/jmo-perspectives/interfaces.py
   cpsskins/branches/jmo-perspectives/relations/tool.py
   cpsskins/branches/jmo-perspectives/thememanager.py
Log:

- simplification: 
  we register the relation storage under the theme management folder as a
  local utility



Modified: cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/rendering/engine.py      
(original)
+++ cpsskins/branches/jmo-perspectives/browser/rendering/engine.py      Tue Nov 
22 15:01:03 2005
@@ -142,7 +142,7 @@
 
         theme = getThemeManager().getThemeInContext(element)
         # TODO:  move the relation storage to the parent folder
-        relations = theme.getStorage(IRelationStorage)
+        relations = getUtility(IRelationStorage, context=element)
         perspective = getMultiAdapter((element, request),
                                        INegociation).getPerspective()
 

Modified: cpsskins/branches/jmo-perspectives/browser/tree/slot.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/tree/slot.py     (original)
+++ cpsskins/branches/jmo-perspectives/browser/tree/slot.py     Tue Nov 22 
15:01:03 2005
@@ -18,7 +18,7 @@
 __docformat__ = "reStructuredText"
 
 from zope.app import zapi
-from zope.component import getMultiAdapter
+from zope.component import getMultiAdapter, getUtility
 from zope.app.container.browser.adding import Adding
 from zope.app.publisher.browser import BrowserView
 from zope.app.traversing.api import getParent
@@ -75,7 +75,7 @@
                 third=perspective,
                 )
 
-        relations = theme.getStorage(IRelationStorage)
+        relations = getUtility(IRelationStorage, context=container)
         relations.add(relation)
 
         content.__parent__ = container
@@ -132,8 +132,7 @@
                 third=perspective,
                 )
 
-        theme = getThemeManager().getThemeInContext(dest_container)
-        relations = theme.getStorage(IRelationStorage)
+        relations = getUtility(IRelationStorage, context=dest_container)
         relations.add(relation)
 
         # remove old src_slot -> portlet relations

Modified: cpsskins/branches/jmo-perspectives/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/interfaces.py    (original)
+++ cpsskins/branches/jmo-perspectives/interfaces.py    Tue Nov 22 15:01:03 2005
@@ -41,6 +41,9 @@
     def getImageCache():
         """Return the image cache."""
 
+    def getRelationStorage():
+        """Return the relation storage."""
+
     def registerElement(element):
         """Add an element to the unique id registry."""
 

Modified: cpsskins/branches/jmo-perspectives/relations/tool.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/relations/tool.py        (original)
+++ cpsskins/branches/jmo-perspectives/relations/tool.py        Tue Nov 22 
15:01:03 2005
@@ -18,6 +18,7 @@
 __docformat__ = "reStructuredText"
 
 from zope.interface import implements
+from zope.component import getUtility
 
 from cpsskins.relations.interfaces import IRelationTool, IRelationStorage
 from cpsskins.utils import getThemeManager
@@ -28,11 +29,8 @@
 
     def __init__(self, context):
         self.context = context
-
         # Set the storage
-        tmutil = getThemeManager()
-        theme = tmutil.getThemeInContext(context)
-        self.storage = theme.getStorage(IRelationStorage)
+        self.storage = getUtility(IRelationStorage, context=context)
 
     def getStorage(self):
         return self.storage

Modified: cpsskins/branches/jmo-perspectives/thememanager.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/thememanager.py  (original)
+++ cpsskins/branches/jmo-perspectives/thememanager.py  Tue Nov 22 15:01:03 2005
@@ -35,6 +35,7 @@
 from cpsskins.ontology import isDefault, hasFormat, hasDisplay
 from cpsskins.relations import MonadicRelation
 from cpsskins.relations.tool import RelationTool
+from cpsskins.relations.storage import RelationStorage
 from cpsskins.relations.interfaces import IRelationStorage
 
 def added(object, event):
@@ -62,11 +63,13 @@
         self['uids'] = IntIds()
         self['imagecache'] = ImageCache()
         self['settings'] = Settings()
+        self['relations'] = RelationStorage()
 
     def registerUtilities(self):
         self.registerUtility(IIntIds, self['uids'])
         self.registerUtility(IImageCache, self['imagecache'])
         self.registerUtility(ISettings, self['settings'])
+        self.registerUtility(IRelationStorage, self['relations'])
 
     def registerUtility(self, interface, utility):
         reg = UtilityRegistration('', interface, utility)
@@ -79,6 +82,9 @@
     def getImageCache(self):
         return getUtility(IImageCache, context=self)
 
+    def getRelationStorage(self):
+        return getUtility(IRelationStorage, context=self)
+
     def registerElement(self, element):
         id = self.getIdRegistry().register(element)
         # store the element's id in the element itself.
@@ -109,8 +115,7 @@
     def isDefault(self, object=None):
         """Return True if the element is used by default
         """
-        theme = self.getThemeInContext(object)
-        relations = theme.getStorage(IRelationStorage)
+        relations = getUtility(IRelationStorage, context=object)
         res = relations.search(predicate=isDefault, first=object)
         return res is not []
 
@@ -160,9 +165,8 @@
     def setAsDefault(self, object=None):
         """Set the default theme
         """
-        theme = self.getThemeInContext(object)
         relation = MonadicRelation(isDefault, object)
-        relations = theme.getStorage(IRelationStorage)
+        relations = getUtility(IRelationStorage, context=object)
         relations.add(relation)
 
     def removeDisplays(self, object):
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to