[Zope-CVS] CVS: Products/CompositePage - composite.py:1.23 interfaces.py:1.13

Sidnei da Silva sidnei at awkly.org
Thu Apr 15 13:41:34 EDT 2004


Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv24472

Modified Files:
	composite.py interfaces.py 
Log Message:
Simplify classes a tad, at Shane's request.


=== Products/CompositePage/composite.py 1.22 => 1.23 ===
--- Products/CompositePage/composite.py:1.22	Wed Apr 14 12:15:29 2004
+++ Products/CompositePage/composite.py	Thu Apr 15 13:41:33 2004
@@ -42,16 +42,6 @@
     def all_meta_types(self):
         return Folder.all_meta_types(self, interfaces=(ISlot,))
 
-class SlotContainer(Acquisition.Implicit):
-    """ A dummy slots container for the base implementation of
-    SlotGenerator.
-    """
-
-    def get(self, name, default=None):
-        raise KeyError, name
-
-    __getitem__ = get
-
 class SlotGenerator(Acquisition.Explicit):
     """Automatically makes slots available to the template.
 
@@ -59,13 +49,25 @@
     """
     _slot_class = Slot
 
-    def newSlot(self, name):
-        return self._slot_class(name)
+    def getSlots(self, composite=None):
+        if composite is None:
+            composite = self._getComposite()
+        return composite.filled_slots
+
+    def _getComposite(self):
+        return aq_parent(aq_inner(self))
 
-    def getSlots(self, context=None):
-        if context is None:
-            context = aq_parent(aq_inner(self))
-        return SlotContainer().__of__(context)
+    def newSlot(self, name, composite=None):
+        # Generate a new slot.
+        s = self._slot_class(name)
+        if composite is None:
+            composite = self._getComposite()
+        if composite.isEditing():
+            # Persist the slot.
+            slots = self.getSlots(composite)
+            slots._setObject(s.getId(), s)
+        # else don't persist the slot.
+        return s
 
     def get(self, name, class_name=None, title=None):
         """Returns a slot by name.
@@ -86,31 +88,10 @@
         try:
             return slots[name]
         except (KeyError, AttributeError):
-            return self.newSlot(name).__of__(slots)
+            return self.newSlot(name, composite).__of__(slots)
 
     __getitem__ = get
 
-class FolderSlotGenerator(SlotGenerator):
-
-    def getSlots(self, context=None):
-        if context is None:
-            context = self._getComposite()
-        return context.filled_slots
-
-    def _getComposite(self):
-        return aq_parent(aq_inner(self))
-
-    def newSlot(self, name):
-        # Generate a new slot.
-        s = SlotGenerator.newSlot(self, name)
-        composite = self._getComposite()
-        if composite.isEditing():
-            # Persist the slot.
-            slots = self.getSlots(composite)
-            slots._setObject(s.getId(), s)
-        # else don't persist the slot.
-        return s
-
 class CompositeMixin:
     """ An HTML fragment composed from a template and fragments.
     """
@@ -134,7 +115,7 @@
     _v_slot_specs = None  # [{'name', 'class', 'title'}]
 
     security.declarePublic("slots")
-    slots = FolderSlotGenerator()
+    slots = SlotGenerator()
 
     _properties = (
         {"id": "template_path", "mode": "w", "type": "string",


=== Products/CompositePage/interfaces.py 1.12 => 1.13 ===
--- Products/CompositePage/interfaces.py:1.12	Wed Apr 14 12:15:29 2004
+++ Products/CompositePage/interfaces.py	Thu Apr 15 13:41:33 2004
@@ -47,13 +47,13 @@
         """Returns a slot, creating it if it does not yet exist.
         """
 
-    def getSlots(context=None):
+    def getSlots(composite=None):
         """Returns the slots container, which should have at
         least __getitem__ and raise a KeyError if the slot
         doesn't exists.
         """
 
-    def newSlot(name):
+    def newSlot(name, composite=None):
         """Create a new slot, and optionally add it to the
         slots container.
         """




More information about the Zope-CVS mailing list