Author: jmorliaguet Date: Sun Oct 9 22:32:41 2005 New Revision: 28094 Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/elements/slot.py z3lab/cpsskins/branches/jmo-perspectives/elements/slot.py z3lab/cpsskins/branches/jmo-perspectives/interfaces.py z3lab/cpsskins/branches/jmo-perspectives/thememanager.py Log:
- docstring updates - moved slot specific methods from thememanager.py to browser/elements/slot.py 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 Sun Oct 9 22:32:41 2005 @@ -26,8 +26,12 @@ from cpsskins.browser.negociation.interfaces import INegociation from cpsskins.elements.interfaces import IDisplayable from cpsskins.elements.interfaces import IPortlet +from cpsskins.ontology import hasPortlet, hasPortletFromPerspective +from cpsskins.relations import DyadicRelation, TriadicRelation +from cpsskins.relations.tool import RelationTool from cpsskins.thememanager import getThemeManager from interfaces import INodeAdding, INodeRemoving, INodeOrdering, INodeMoving +from cpsskins.storage.interfaces import IPortletStorage, IRelationStorage class SlotAdding(Adding): """A view for adding elements into slots @@ -50,22 +54,35 @@ # a slot is not a container, it is a collection of references to # portlets that are physically stored in a portlet folder. tmutil = getThemeManager() - portlet = tmutil.addPortlet( - slot=container, - portlet=content, - perspective=perspective, - ) + theme = tmutil.getThemeInContext(container) + portlets = theme.getStorage(IPortletStorage) + portlets.add(content) + + if perspective is None: + relation = DyadicRelation( + predicate=hasPortlet, + first=container, + second=content, + ) + else: + relation = TriadicRelation( + predicate=hasPortletFromPerspective, + first=container, + second=content, + third=perspective, + ) + + relations = theme.getStorage(IRelationStorage) + relations.add(relation) - portlet.__parent__ = container + content.__parent__ = container # store the portlet's order in the slot's "BoxGroup" display # XXX to refactor - getDisplay = IDisplayable(container).getDisplay - default = getDisplay() - display = getDisplay(perspective, default) - display.append(portlet) + display = IDisplayable(container).getDisplay(perspective) + display.append(content) - return portlet + return content class SlotMoving(BrowserView): """A view for moving elements between slots @@ -79,16 +96,49 @@ if dest_container == src_container: return content - tmutil = getThemeManager() - # the element is not physically moved but slot -> portlet relations # need to be updated. - tmutil.movePortlet( - src_slot=src_container, - dest_slot=dest_container, - portlet=content, + + reltool = RelationTool(content) + + # TODO: let compound predicates support predicates of different arities + old_relations = reltool.search( + predicate=hasPortlet, + first=src_container, + second=content, + ) + reltool.search( + predicate=hasPortletFromPerspective, + first=src_container, + second=content, ) + rel = reltool.get(old_relations[0]) + perspective = len(rel) == 3 and rel.third or None + + # set the dest_slot -> portlet relation + if perspective is None: + relation = DyadicRelation( + predicate=hasPortlet, + first=dest_container, + second=content, + ) + else: + relation = TriadicRelation( + predicate=hasPortletFromPerspective, + first=dest_container, + second=content, + third=perspective, + ) + + theme = getThemeManager().getThemeInContext(dest_container) + relations = theme.getStorage(IRelationStorage) + relations.add(relation) + + # remove old src_slot -> portlet relations + reltool.remove(old_relations) + # set the portlet's parent explicitly + content.__parent__ = dest_container + return content class SlotRemoving(BrowserView): @@ -109,18 +159,29 @@ interface=INegociation, ).getPerspective() - tmutil = getThemeManager() - tmutil.removePortlet( - slot=container, - portlet=content, - perspective=perspective, - ) + theme = getThemeManager().getThemeInContext(container) + portlets = theme.getStorage(IPortletStorage) + + reltool = RelationTool(container) + if perspective is None: + ids = reltool.search( + predicate=hasPortlet, + first=container, + second=content, + ) + else: + ids = reltool.search( + predicate=hasPortletFromPerspective, + first=container, + second=content, + third=perspective, + ) + + reltool.remove(ids) + del portlets[content.name()] # store the portlet's order in the slot's "BoxGroup" display - # XXX to refactor - getDisplay = IDisplayable(container).getDisplay - default = getDisplay() - display = getDisplay(perspective, default) + display = IDisplayable(container).getDisplay(perspective) display.remove(content) class SlotOrdering(BrowserView): Modified: z3lab/cpsskins/branches/jmo-perspectives/elements/slot.py ============================================================================== --- z3lab/cpsskins/branches/jmo-perspectives/elements/slot.py (original) +++ z3lab/cpsskins/branches/jmo-perspectives/elements/slot.py Sun Oct 9 22:32:41 2005 @@ -93,8 +93,11 @@ return portlets def __getitem__(self, name): + """Get a portlet by name""" tmutil = getThemeManager() - return tmutil.getPortlet(container=self, name=name) + theme = tmutil.getThemeInContext(self) + portlets = theme.getStorage(IPortletStorage) + return portlets[name] def __setitem__(self, name, object): raise NotImplementedError( Modified: z3lab/cpsskins/branches/jmo-perspectives/interfaces.py ============================================================================== --- z3lab/cpsskins/branches/jmo-perspectives/interfaces.py (original) +++ z3lab/cpsskins/branches/jmo-perspectives/interfaces.py Sun Oct 9 22:32:41 2005 @@ -26,31 +26,34 @@ # Theme management class IThemeManagement(Interface): - """Interface for theme management.""" + """Interface for theme management. + + The methods may be moved to other classes. + """ def getIdRegistry(): - """Return the uid registry""" + """Return the unique id registry.""" def getImageCache(): - """Return the image cache""" + """Return the image cache.""" def registerElement(element): - """Register an element""" + """Add an element to the unique id registry.""" def unregisterElement(element): - """Unregister an element""" + """Remove an element from the unique id registry.""" def getElementById(id): - """ """ + """Return an element by its unique id. """ def getThemes(): - """Return the list of themes""" + """Return the list of available themes.""" def getDefaultTheme(): - """Return the default theme""" + """Return the default theme.""" def getDefaultPage(): - """Return the default page""" + """Return the default page.""" def getEffectiveTheme(context, request): """Return the effective theme @@ -61,24 +64,18 @@ (the one that will be effectively displayed)""" def getThemeInContext(context): - """Return the theme in which the element is located + """Return the theme in which the element is located. + + A context must be provided with. """ def getPageInContext(context): """Return the page in which the element is located - """ - def getPortlet(container, name): - """Get a portlet from the storage + A context must be provided with. """ - def setPortlet(slot, portlet, perspective): - """Set a portlet in the a slot - """ - - def addPortlet(slot, portlet, perspective): - """Add a portlet to a slot - """ + # TODO: move somewhere else def removeDisplays(object): """Remove the display of an element """ Modified: z3lab/cpsskins/branches/jmo-perspectives/thememanager.py ============================================================================== --- z3lab/cpsskins/branches/jmo-perspectives/thememanager.py (original) +++ z3lab/cpsskins/branches/jmo-perspectives/thememanager.py Sun Oct 9 22:32:41 2005 @@ -30,10 +30,9 @@ from ontology import isDefault, hasFormat from ontology import hasDisplay, hasDisplay, hasDisplayFromPerspective from ontology import hasPortlet, hasPortletFromPerspective -from relations import MonadicRelation, DyadicRelation, TriadicRelation +from relations import MonadicRelation from relations.tool import RelationTool -from storage.interfaces import \ - IRelationStorage, IFormatStorage, IPortletStorage +from storage.interfaces import IRelationStorage THEMES_MANAGER_NAME = 'themes' UIDS_NAME = 'uids' @@ -170,91 +169,6 @@ relations = theme.getStorage(IRelationStorage) relations.add(relation) - def getPortlet(self, container=None, name=None): - """Get a portlet by name""" - theme = self.getThemeInContext(container) - portlets = theme.getStorage(IPortletStorage) - return portlets[name] - - def movePortlet(self, src_slot, dest_slot, portlet): - """Move a portlet between slots. - """ - reltool = RelationTool(portlet) - - # TODO: let compound predicates support predicates of different arities - old_relations = reltool.search( - predicate=hasPortlet, - first=src_slot, - second=portlet, - ) + reltool.search( - predicate=hasPortletFromPerspective, - first=src_slot, - second=portlet, - ) - rel = reltool.get(old_relations[0]) - perspective = len(rel) == 3 and rel.third or None - # set the dest_slot -> portlet relation - self.setPortlet(dest_slot, portlet, perspective) - # remove old src_slot -> portlet relations - reltool.remove(old_relations) - # set the portlet's parent explicitly - portlet.__parent__ = dest_slot - - def addPortlet(self, slot, portlet, perspective): - """Add a portlet to a slot - """ - theme = self.getThemeInContext(slot) - portlets = theme.getStorage(IPortletStorage) - portlets.add(portlet) - - self.setPortlet(slot, portlet, perspective) - return portlet - - def setPortlet(self, slot, portlet, perspective): - """Set a portlet in a slot - """ - if perspective is None: - relation = DyadicRelation( - predicate=hasPortlet, - first=slot, - second=portlet, - ) - else: - relation = TriadicRelation( - predicate=hasPortletFromPerspective, - first=slot, - second=portlet, - third=perspective, - ) - - theme = self.getThemeInContext(slot) - relations = theme.getStorage(IRelationStorage) - relations.add(relation) - - def removePortlet(self, slot, portlet, perspective=None): - """Remove a portlet - """ - theme = self.getThemeInContext(slot) - portlets = theme.getStorage(IPortletStorage) - - reltool = RelationTool(slot) - if perspective is None: - ids = reltool.search( - predicate=hasPortlet, - first=slot, - second=portlet, - ) - else: - ids = reltool.search( - predicate=hasPortletFromPerspective, - first=slot, - second=portlet, - third=perspective, - ) - - reltool.remove(ids) - del portlets[portlet.name()] - def removeDisplays(self, object): """Remove the displays of a given element """ -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins