Author: jmorliaguet
Date: Sun Nov 20 22:41:26 2005
New Revision: 1908

Modified:
   cpsskins/branches/jmo-perspectives/configuration/interfaces.py
   cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
   
cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
   cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
   cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py
   cpsskins/branches/jmo-perspectives/interfaces.py
   cpsskins/branches/jmo-perspectives/resources/manager.py
   cpsskins/branches/jmo-perspectives/settings.py
Log:

- small refactoring of the resource manager / registration of resources.
  simplifications



Modified: cpsskins/branches/jmo-perspectives/configuration/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/configuration/interfaces.py      
(original)
+++ cpsskins/branches/jmo-perspectives/configuration/interfaces.py      Sun Nov 
20 22:41:26 2005
@@ -31,7 +31,3 @@
     def unregister(name):
        """Unregister an entry by its name"""
 
-class IResource(Interface):
-
-    def getResource():
-        """Return the resource."""

Modified: 
cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml    
    (original)
+++ 
cpsskins/branches/jmo-perspectives/configuration/perspectives/configure.zcml    
    Sun Nov 20 22:41:26 2005
@@ -12,7 +12,8 @@
   </localUtility>
 
   <adapter
-      factory=".perspective.Resource"
+      for=".perspective.IPerspective"
+      factory="cpsskins.settings.Resource"
   />
 
 </configure>

Modified: 
cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py  
    (original)
+++ 
cpsskins/branches/jmo-perspectives/configuration/perspectives/metaconfigure.py  
    Sun Nov 20 22:41:26 2005
@@ -23,8 +23,9 @@
 
 from cpsskins import configuration
 from cpsskins.interfaces import ISettingType
-from cpsskins.perspectives import Perspective
+from cpsskins.perspectives import Perspective, Resources
 from cpsskins.perspectives.interfaces import IPerspective
+from cpsskins.resources.manager import IResourceManager
 
 alsoProvides(configuration.IPerspective, ISettingType)
 
@@ -39,9 +40,7 @@
 
     # register as a global setting
     resource_object = getUtility(IPerspective, resource)
-    setting = configuration.Perspective(title=resource_object.title,
-                                        readonly=True,
-                                        resource=resource_object)
-
-    provideUtility(setting, configuration.IPerspective, name)
+    resources = Resources(resource_object)
+    resources.register(name=name, title=resource_object.title,
+                       resource=resource_object)
 

Modified: 
cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py    
    (original)
+++ 
cpsskins/branches/jmo-perspectives/configuration/perspectives/perspective.py    
    Sun Nov 20 22:41:26 2005
@@ -18,13 +18,10 @@
 
 __docformat__ = "reStructuredText"
 
-from zope.component import adapts
 from zope.interface import implements, Interface, Attribute
-
 from persistent import Persistent
 from zope.app.container.contained import Contained
 
-from cpsskins.configuration.interfaces import IResource
 from cpsskins.interfaces import ISetting
 
 class IPerspective(ISetting):
@@ -40,16 +37,3 @@
         self.readonly = readonly
         self.resource = resource
 
-class Resource(object):
-    """This adapter turns perspective configuration items into resources that
-    can natively be used by the application.
-    """
-    adapts(IPerspective)
-    implements(IResource)
-
-    def __init__(self, context):
-        self.context = context
-
-    def getResource(self):
-        return self.context.resource
-

Modified: cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py  
(original)
+++ cpsskins/branches/jmo-perspectives/engines/sitedesigner/browser.py  Sun Nov 
20 22:41:26 2005
@@ -22,8 +22,7 @@
 from zope.app.interface import queryType
 from zope import xmlpickle 
 
-from cpsskins.configuration.interfaces import IResource
-from cpsskins.interfaces import ISettings, ISetting, ISettingType
+from cpsskins.interfaces import ISettings, ISetting, ISettingType, IResource
 from cpsskins.resources.manager import IResourceManager
 
 class SiteDesignerView(BrowserView):

Modified: cpsskins/branches/jmo-perspectives/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/interfaces.py    (original)
+++ cpsskins/branches/jmo-perspectives/interfaces.py    Sun Nov 20 22:41:26 2005
@@ -113,3 +113,7 @@
 
     resource = Attribute("The resource.")
 
+class IResource(Interface):
+
+    def getResource():
+        """Return the resource."""

Modified: cpsskins/branches/jmo-perspectives/resources/manager.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/resources/manager.py     (original)
+++ cpsskins/branches/jmo-perspectives/resources/manager.py     Sun Nov 20 
22:41:26 2005
@@ -22,10 +22,10 @@
 from zope.app.container.interfaces import INameChooser
 from zope.app.location.pickling import locationCopy
 from zope.interface import implements, Interface
-from zope.component import getUtilitiesFor, queryUtility, getUtility
+from zope.component import (getUtilitiesFor, queryUtility, getUtility,
+                            provideUtility)
 
-from cpsskins.configuration.interfaces import IResource
-from cpsskins.interfaces import ISettings
+from cpsskins.interfaces import ISettings, IResource
 
 class IResourceManager(Interface):
     """A resource manager is used to manage the resource used by the
@@ -63,18 +63,26 @@
         self.context = context
 
     def register(self, name=u'', title=u'', resource=None, context=None):
-        """Register a local resource."""
-        if context is None:
-            raise ValueError("Must specify a context.")
+        """Register the setting as a utility.
+        """
+        factory = self.setting_factory
 
-        settings = getUtility(ISettings, context=context)
-        chooser = INameChooser(settings)
-        name = name or chooser.chooseName(title, object)
-        settings[name] = self.setting_factory(title=title, resource=resource)
-
-        reg = UtilityRegistration(name, self.setting_type, settings[name])
-        settings.registrationManager.addRegistration(reg)
-        reg.status = ActiveStatus
+        # register as a global utility
+        if context is None:
+            setting = factory(title=title, resource=resource, readonly=True)
+           print repr(setting)
+            provideUtility(setting, self.setting_type, name)
+
+        # register as a local utility
+        else:
+            settings = getUtility(ISettings, context=context)
+            chooser = INameChooser(settings)
+            name = name or chooser.chooseName(title, object)
+            settings[name] = factory(title=title, 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:
@@ -112,3 +120,4 @@
 
         self.register(name=name, title=setting.title, resource=resource,
                       context=context)
+

Modified: cpsskins/branches/jmo-perspectives/settings.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/settings.py      (original)
+++ cpsskins/branches/jmo-perspectives/settings.py      Sun Nov 20 22:41:26 2005
@@ -18,10 +18,24 @@
 __docformat__ = "reStructuredText"
 
 from zope.app.component.site import SiteManagementFolder
+from zope.component import adapts
 from zope.interface import implements
 
-from interfaces import ISettings
+from interfaces import IResource, ISettings
 
 class Settings(SiteManagementFolder):
 
     implements(ISettings)
+
+class Resource(object):
+    """This adapts settings to resources
+    """
+    adapts(ISettings)
+    implements(IResource)
+
+    def __init__(self, context):
+        self.context = context
+
+    def getResource(self):
+        return self.context.resource
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to