Author: jmorliaguet
Date: Sat Nov 12 14:35:14 2005
New Revision: 29476

Added:
   z3lab/cpsskins/branches/jmo-perspectives/resources/
   z3lab/cpsskins/branches/jmo-perspectives/resources/__init__.py   (contents, 
props changed)
   z3lab/cpsskins/branches/jmo-perspectives/resources/interfaces.py   
(contents, props changed)
   z3lab/cpsskins/branches/jmo-perspectives/resources/manager.py   (contents, 
props changed)
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/perspective.py
   z3lab/cpsskins/branches/jmo-perspectives/elements/theme.py
   z3lab/cpsskins/branches/jmo-perspectives/engines/authoring/authoring.py
   z3lab/cpsskins/branches/jmo-perspectives/interfaces.py
   z3lab/cpsskins/branches/jmo-perspectives/perspectives/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/perspectives/configure.zcml
   z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py
Log:

- added a resource manager (currently used by perspectives)



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 
    Sat Nov 12 14:35:14 2005
@@ -18,8 +18,8 @@
         <p>The presentations associated to this element are listed in the 
table below:</p>
         <table class="inline" cellpadding="0" cellspacing="1">
           <tr>
+            <th>Perspective</th>
             <th>Presentation</th>
-            <th>Display</th>
             <th style="text-align: center"
                 tal:repeat="format_name format_names">
               <tal:block content="format_name" />

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        
Sat Nov 12 14:35:14 2005
@@ -19,8 +19,6 @@
 
 from zope.app.interface import Interface
 
-from cpsskins import interfaces
-
 class IRegistry(Interface):
     """Configuration registry
 

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
  Sat Nov 12 14:35:14 2005
@@ -25,7 +25,6 @@
 from persistent import Persistent
 from zope.app.container.contained import Contained
 
-from cpsskins import interfaces
 from cpsskins.configuration.interfaces import IResource
 
 class IPerspective(Interface):

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  Sat Nov 12 
14:35:14 2005
@@ -18,9 +18,8 @@
 __docformat__ = "reStructuredText"
 
 from zope.app.container.interfaces import INameChooser
-from zope.app.component.interfaces.registration import ActiveStatus
-from zope.app.component.site import SiteManagementFolder, UtilityRegistration
-from zope.component import adapts, queryUtility, getUtilitiesFor
+from zope.app.component.site import SiteManagementFolder
+from zope.component import adapts, queryUtility, getUtilitiesFor, getUtility
 from zope.interface import implements
 
 from cpsskins import configuration
@@ -31,6 +30,7 @@
 from cpsskins.thememanager import getThemeManager
 from interfaces import ITheme, IThemePage
 from interfaces import IPageContainer
+from cpsskins.resources.interfaces import IResourceManager
 
 class Theme(SiteManagementFolder):
     """Theme
@@ -89,32 +89,17 @@
 
     def getPerspectiveById(self, id):
         """Return a perspective by id."""
-        item = queryUtility(configuration.IPerspective, id, context=self)
-        if item is None:
-            return None
-        return IResource(item).getResource()
+        return getUtility(IResourceManager, 'perspectives').lookup(id, self)
 
     def addPerspective(self, name, title):
         """Add a perspective to the perspective storage
         """
         perspective = Perspective(name=name, title=title)
-        settings = getThemeManager()['settings']
-
-        chooser = INameChooser(settings)
-        name = chooser.chooseName(name, perspective)
-        settings[name] = configuration.Perspective(resource=perspective)
-
-        reg = UtilityRegistration(name, configuration.IPerspective,
-                                  settings[name])
-        settings.registrationManager.addRegistration(reg)
-        reg.status = ActiveStatus
+        mgr = getUtility(IResourceManager, 'perspectives')
+        mgr.register(resource=perspective, context=self)
 
     def listPerspectives(self):
-        info = []
-        for name, item in getUtilitiesFor(configuration.IPerspective):
-            resource = IResource(item).getResource()
-            info.append(resource)
-        return info
+        return getUtility(IResourceManager, 'perspectives').list(self)
 
 class NodeTraverser(object):
     """This adapter makes theme nodes traversable.

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/engines/authoring/authoring.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/engines/authoring/authoring.py     
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/engines/authoring/authoring.py     
Sat Nov 12 14:35:14 2005
@@ -20,7 +20,7 @@
 from zope.app.publisher.browser import BrowserView
 from zope.app.session.interfaces import ISession
 from zope.app.zapi import getMultiAdapter
-from zope.component import adapts
+from zope.component import adapts, getUtility
 from zope.interface import implements, Interface
 from zope.security.proxy import removeSecurityProxy
 
@@ -28,6 +28,7 @@
 from cpsskins.elements.interfaces import IDisplayable, IFormattable
 from cpsskins.browser.rendering.interfaces import IViewer
 from cpsskins.thememanager import getThemeManager
+from cpsskins.resources.interfaces import IResourceManager
 
 class IAuthoring(Interface):
 
@@ -76,9 +77,8 @@
         if not perspective:
             del session['perspective']
         else:
-            tmutil = getThemeManager()
-            theme = tmutil.getEffectiveTheme(self.context)
-            perspective = theme.getPerspectiveById(perspective)
+            perspectives = getUtility(IResourceManager, 'perspectives')
+            perspective = perspectives.lookup(perspective, 
context=self.context)
 
             # remove the security proxy before storing the object in the 
session
             perspective = removeSecurityProxy(perspective)
@@ -93,39 +93,34 @@
         - by associating the original display's formats to the new display
 
         """
-        tmutil = getThemeManager()
-        theme = tmutil.getEffectiveTheme(self.context)
-        perspective = theme.getPerspectiveById(perspective)
+        perspectives = getUtility(IResourceManager, 'perspectives')
+        perspective = perspectives.lookup(perspective, context=self.context)
         display = IDisplayable(self.context).getDisplay(perspective)
         if display is None:
             IPresentable(self.context).clonePresentation(perspective)
         self._redirect()
 
     def addPresentation(self, perspective=None):
-        tmutil = getThemeManager()
-        theme = tmutil.getEffectiveTheme(self.context)
-        perspective = theme.getPerspectiveById(perspective)
+        perspectives = getUtility(IResourceManager, 'perspectives')
+        perspective = perspectives.lookup(perspective, context=self.context)
         IPresentable(self.context).addPresentation(perspective)
         self._redirect()
 
     def removePresentation(self, perspective=None):
-        tmutil = getThemeManager()
-        theme = tmutil.getEffectiveTheme(self.context)
-        perspective = theme.getPerspectiveById(perspective)
+        perspectives = getUtility(IResourceManager, 'perspectives')
+        perspective = perspectives.lookup(perspective, context=self.context)
         IPresentable(self.context).removePresentation(perspective)
         self._redirect()
 
     def customizeFormat(self, name='', perspective=None):
-        tmutil = getThemeManager()
-        theme = tmutil.getEffectiveTheme(self.context)
-        perspective = theme.getPerspectiveById(perspective)
+        perspectives = getUtility(IResourceManager, 'perspectives')
+        perspective = perspectives.lookup(perspective, context=self.context)
         IPresentable(self.context).customizeFormat(name, perspective)
         self._redirect()
 
     def uncustomizeFormat(self, name='', perspective=None):
-        tmutil = getThemeManager()
-        theme = tmutil.getEffectiveTheme(self.context)
-        perspective = theme.getPerspectiveById(perspective)
+        perspectives = getUtility(IResourceManager, 'perspectives')
+        perspective = perspectives.lookup(perspective, context=self.context)
         IPresentable(self.context).uncustomizeFormat(name, perspective)
         self._redirect()
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/interfaces.py      (original)
+++ z3lab/cpsskins/branches/jmo-perspectives/interfaces.py      Sat Nov 12 
14:35:14 2005
@@ -22,7 +22,6 @@
 from zope.i18nmessageid import MessageFactory
 
 from cpsskins.elements.interfaces import IElement, IPortlet, IDisplay, IFormat
-from cpsskins.perspectives.interfaces import IPerspective
 
 _ = MessageFactory("cpsskins")
 

Modified: z3lab/cpsskins/branches/jmo-perspectives/perspectives/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/perspectives/__init__.py   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/perspectives/__init__.py   Sat Nov 
12 14:35:14 2005
@@ -20,6 +20,8 @@
 from persistent import Persistent
 from zope.interface import implements
 
+from cpsskins import configuration
+from cpsskins.resources.manager import ResourceManager
 from interfaces import IPerspective
 
 class Perspective(object):
@@ -45,7 +47,6 @@
     def __eq__(self, other):
         return str(self) == other
 
-
 class Relatable(object):
     """This adapter makes perspectives relatable.
     """
@@ -54,3 +55,8 @@
 
     def __str__(self):
         return str(self.context)
+
+class Resources(ResourceManager):
+    setting_type = configuration.IPerspective
+    setting_factory = configuration.Perspective
+

Modified: z3lab/cpsskins/branches/jmo-perspectives/perspectives/configure.zcml
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/perspectives/configure.zcml        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/perspectives/configure.zcml        
Sat Nov 12 14:35:14 2005
@@ -26,4 +26,12 @@
 
   </content>
 
+  <!-- Resource management utility -->
+
+  <utility
+      name="perspectives"
+      provides="cpsskins.resources.manager.IResourceManager"
+      factory=".Resources"
+  />
+
 </configure>

Added: z3lab/cpsskins/branches/jmo-perspectives/resources/__init__.py
==============================================================================
--- (empty file)
+++ z3lab/cpsskins/branches/jmo-perspectives/resources/__init__.py      Sat Nov 
12 14:35:14 2005
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+

Added: z3lab/cpsskins/branches/jmo-perspectives/resources/interfaces.py
==============================================================================
--- (empty file)
+++ z3lab/cpsskins/branches/jmo-perspectives/resources/interfaces.py    Sat Nov 
12 14:35:14 2005
@@ -0,0 +1,20 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from manager import IResourceManager

Added: z3lab/cpsskins/branches/jmo-perspectives/resources/manager.py
==============================================================================
--- (empty file)
+++ z3lab/cpsskins/branches/jmo-perspectives/resources/manager.py       Sat Nov 
12 14:35:14 2005
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Resource manager
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.app.component.interfaces.registration import ActiveStatus
+from zope.app.component.site import SiteManagementFolder, UtilityRegistration
+from zope.app.container.interfaces import INameChooser
+from zope.interface import implements, Interface
+from zope.component import getUtilitiesFor, queryUtility, getUtility
+
+from cpsskins.configuration.interfaces import IResource
+from cpsskins.interfaces import ISettings
+
+class IResourceManager(Interface):
+    """A resource manager is used to manage the resource used by the
+    application. Resources can be stored:
+
+    - in a global utility
+
+    - in a local utility
+
+    - in a local storage
+
+    """
+
+    def lookup(name, context, default):
+        """Look up a resource."""
+
+    def register(object, context):
+        """Register a resource."""
+
+class ResourceManager(object):
+    """Resource manager utility"""
+
+    setting_type = None
+    setting_factory = None
+
+    implements(IResourceManager)
+
+    def register(self, resource=None, context=None):
+        """Register a local resource."""
+        if context is None:
+            raise ValueError("Must specify a context.")
+        settings = getUtility(ISettings, context=context)
+
+        chooser = INameChooser(settings)
+        name = chooser.chooseName('', object)
+        settings[name] = self.setting_factory(resource=resource)
+
+        reg = UtilityRegistration(name, self.setting_type, settings[name])
+        settings.registrationManager.addRegistration(reg)
+        reg.status = ActiveStatus
+
+    def lookup(self, name=u'', context=None, default=None):
+        if not name:
+            raise KeyError("Must specify a resource name.")
+
+        setting = queryUtility(self.setting_type, name, context=context)
+        if setting is None:
+            return default
+
+        resource_getter = IResource(setting, None)
+        if resource_getter is not None:
+            return resource_getter.getResource()
+        return default
+
+    def list(self, context=None):
+        resources = []
+        for name, setting in getUtilitiesFor(self.setting_type):
+            resource_getter = IResource(setting, None)
+            if resource_getter is not None:
+                resources.append(resource_getter.getResource())
+        return resources

Modified: z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py      
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py      Sat Nov 
12 14:35:14 2005
@@ -22,6 +22,5 @@
 from displays import IDisplayStorage
 from formats import IFormatStorage
 from relations import IRelationStorage
-from perspectives import IPerspectiveStorage
 from portlets import IPortletStorage
 from resources import IResourceStorage
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to