Author: jmorliaguet
Date: Sat Jun 10 17:13:03 2006
New Revision: 3389

Modified:
   cpsskins/branches/paris-sprint-2006/setup/interfaces.py
   cpsskins/branches/paris-sprint-2006/setup/preset.py

Log:

- made presets implement IReadContainer to make it possible to traverse
  to the resource.



Modified: cpsskins/branches/paris-sprint-2006/setup/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/interfaces.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/interfaces.py     Sat Jun 10 
17:13:03 2006
@@ -17,6 +17,7 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.app.container.interfaces import IReadContainer
 from zope.interface import Interface, Attribute
 from zope.interface.interfaces import IInterface
 from zope.schema import TextLine
@@ -65,7 +66,7 @@
 
 ##### Presets  #######################################################
 
-class IPreset(Interface):
+class IPreset(IReadContainer):
     """Preset"""
 
     name = Attribute(u"The preset's name.")

Modified: cpsskins/branches/paris-sprint-2006/setup/preset.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/preset.py (original)
+++ cpsskins/branches/paris-sprint-2006/setup/preset.py Sat Jun 10 17:13:03 2006
@@ -20,6 +20,7 @@
 from persistent import Persistent
 from zope.app.container.contained import Contained
 from zope.interface import implements
+from zope.location.location import locate
 
 from cpsskins.setup.interfaces import IIdentifiable
 from cpsskins.setup.interfaces import IGlobalPreset, ILocalPreset, IPreset
@@ -29,12 +30,13 @@
     """
     implements(IPreset)
 
+    resource_key = u'resource'
+
     def __init__(self, name=u'', resource=None):
         self.name = name
         self.resource = resource
-        # add a reference from the resource to the preset
-        self.resource.__parent__ = self
-        self.resource.__name__ = u'data'
+        # locate the resource inside the preset itself
+        locate(object=self.resource, parent=self, name=self.resource_key)
 
     def __repr__(self):
         return u'<Preset: %s>' % IIdentifiable(self).getURI()
@@ -42,13 +44,32 @@
     def __call__(self):
         return self.resource
 
+    def keys(self):
+        return [self.resource_key]
+
+    def __getitem__(self, key):
+        if key == self.resource_key:
+            return self.resource
+        raise KeyError("No such item")
+
+    def __iter__(self):
+        return iter(self.keys())
+
+    def items(self):
+        return [(self.resource_key, self.resource)]
+
+    def has_key(self, key):
+        return key == self.resource_key
+
+    def len(self):
+        return 1
+
     def isGlobal(self):
         return IGlobalPreset.providedBy(self)
 
     def isLocal(self):
         return ILocalPreset.providedBy(self)
 
-
 class GlobalPreset(Preset):
     """A local persistent preset
     """
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to