Author: jmorliaguet
Date: Wed Oct 12 17:20:43 2005
New Revision: 28206

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py
   z3lab/cpsskins/branches/jmo-perspectives/browser/renderers/filters/widget.py
   z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/storage/interfaces.py
Log:

- saving work (initial duplication of portlets in slots)



Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py   
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py   Wed Oct 
12 17:20:43 2005
@@ -30,9 +30,10 @@
 from cpsskins.relations import DyadicRelation, TriadicRelation
 from cpsskins.relations.tool import RelationTool
 from cpsskins.thememanager import getThemeManager
+from cpsskins.storage.interfaces import IPortletStorage, IRelationStorage
 from interfaces import INodeAdding, INodeRemoving, INodeOrdering, INodeMoving
 from interfaces import INodeDuplicating
-from cpsskins.storage.interfaces import IPortletStorage, IRelationStorage
+from cpsskins.relations.tool import RelationTool
 
 class SlotAdding(Adding):
     """A view for adding elements into slots
@@ -197,16 +198,14 @@
 
         # So far only portlets can be added into slots.
         if not IPortlet.providedBy(content):
-            raise TypeError("Only portlets can be reordered in slots")
+            raise TypeError("Only portlets can be reordered inside slots")
 
         perspective = getMultiAdapter(
             objects=(container, request),
             interface=INegociation,
             ).getPerspective()
 
-        getDisplay = IDisplayable(container).getDisplay
-        default = getDisplay()
-        display = getDisplay(perspective, default)
+        display = IDisplayable(container).getEffectiveDisplay(perspective)
 
         if content in display:
             display.remove(content)
@@ -219,4 +218,55 @@
     implements(INodeDuplicating)
 
     def duplicate(self, content):
-        pass
+        """Duplicate an element.
+        """
+        container = self.context
+        request = self.request
+
+        if not IPortlet.providedBy(content):
+            raise TypeError("Only portlets can be duplicated inside slots")
+
+        tmutil = getThemeManager()
+        theme = tmutil.getThemeInContext(container)
+        portlets = theme.getStorage(IPortletStorage)
+
+        duplicated = portlets.duplicate(content)
+
+        reltool = RelationTool(content)
+
+        # Manage relations
+        relations = reltool.search(
+            predicate=hasPortlet,
+            first=container,
+            second=content,
+            ) + reltool.search(
+            predicate=hasPortletFromPerspective,
+            first=container,
+            second=content,
+            )
+
+        rel = reltool.get(relations[0])
+        perspective = len(rel) == 3 and rel.third or None
+
+        display = IDisplayable(container).getEffectiveDisplay(perspective)
+        display.insert(0, duplicated)
+
+        # set the dest_slot -> portlet relation
+        if perspective is None:
+            relation = DyadicRelation(
+                predicate=hasPortlet,
+                first=container,
+                second=duplicated,
+                )
+        else:
+            relation = TriadicRelation(
+                predicate=hasPortletFromPerspective,
+                first=container,
+                second=duplicated,
+                third=perspective,
+                )
+
+        reltool.add(relation)
+
+        return duplicated.getIdentifier()
+

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/browser/renderers/filters/widget.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/browser/renderers/filters/widget.py    
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/browser/renderers/filters/widget.py    
    Wed Oct 12 17:20:43 2005
@@ -182,7 +182,9 @@
 class BasicImageView(WidgetView):
     """Display an image with minimal formatting
     """
-    # TODO
+    def __call__(self, data, **kw):
+        # TODO
+        return '<div>%s</div>' % data.content()
 
 class BasicItemView(WidgetView):
     """Display an item with minimal formatting

Modified: z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/storage/__init__.py        Wed Oct 
12 17:20:43 2005
@@ -21,6 +21,8 @@
 from zope.app.container.contained import Contained
 from zope.app.container.contained import ObjectAddedEvent, ObjectRemovedEvent
 from zope.app.container.interfaces import INameChooser
+from zope.app.event.objectevent import ObjectCopiedEvent
+from zope.app.location.pickling import locationCopy
 from zope.event import notify
 from zope.interface import implements
 
@@ -33,6 +35,8 @@
     implements(IStorage)
 
     def add(self, object, name=''):
+        """Add an object to the storage.
+        """
         chooser = INameChooser(self)
         name = chooser.chooseName(name, object)
         self[name] = object
@@ -40,6 +44,8 @@
         return self[name]
 
     def remove(self, objects):
+        """Remove an object from the storage.
+        """
         if not isinstance(objects, (list, tuple)):
             objects = [objects]
         for obj in objects:
@@ -48,3 +54,21 @@
             if obj not in self:
                 raise KeyError("%s not in the storage." % obj)
             del self[obj]
+
+    def duplicate(self, object):
+        """Duplicate an object in the storage.
+
+        Return the object of the duplication.
+        """
+        name = object.name()
+        if object.name() not in self:
+            raise KeyError("%s not in the storage." % object)
+
+        chooser = INameChooser(self)
+        copy = locationCopy(object)
+        new_name = chooser.chooseName(name, copy)
+
+        notify(ObjectCopiedEvent(copy))
+        self[new_name] = copy
+
+        return self[new_name]

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      Wed Oct 
12 17:20:43 2005
@@ -27,10 +27,14 @@
 class IStorage(Interface):
 
     def add(object):
-        """ """
+        """Add an object to the storage. Return the added object."""
 
     def remove(objects):
-        """ """
+        """Remove an object from the storage."""
+
+    def duplicate(object):
+        """Duplicated an object in the storage.
+        Return the object of the duplication."""
 
     def __setitem__(item):
         """ """
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to