[Zope-CVS] CVS: Products/CompositePage - __init__.py:1.4.2.2
composite.py:1.9.2.2 designuis.py:1.1.2.2
Shane Hathaway
shane at zope.com
Fri Feb 20 17:31:36 EST 2004
Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv19629
Modified Files:
Tag: composite-flat-ui-branch
__init__.py composite.py designuis.py
Log Message:
Modified the strategy for the manual slotting interface.
A skin method will call upon a composite and a UI object to
get the current slot contents and script/style fragments.
=== Products/CompositePage/__init__.py 1.4.2.1 => 1.4.2.2 ===
--- Products/CompositePage/__init__.py:1.4.2.1 Fri Feb 20 11:59:46 2004
+++ Products/CompositePage/__init__.py Fri Feb 20 17:31:35 2004
@@ -20,7 +20,6 @@
tool.registerUI("common", designuis.CommonUI())
tool.registerUI("zmi", designuis.ZMIUI())
tool.registerUI("cmf", designuis.CMFUI())
-tool.registerUI("manual", designuis.ManualUI())
def initialize(context):
=== Products/CompositePage/composite.py 1.9.2.1 => 1.9.2.2 ===
--- Products/CompositePage/composite.py:1.9.2.1 Fri Feb 20 11:59:46 2004
+++ Products/CompositePage/composite.py Fri Feb 20 17:31:35 2004
@@ -87,6 +87,7 @@
+ Folder.manage_options[2:]
)
+ default_ui = "common"
template_path = "template"
_v_editing = 0
_v_rendering = 0
@@ -152,19 +153,14 @@
index_html = None
security.declareProtected(perm_names.change_composites, "design")
- def design(self, ui="common"):
+ def design(self, ui=None):
"""Renders the composite with editing features.
"""
- tool = aq_get(self, "composite_tool", None, 1)
- if tool is None:
- raise CompositeError("No composite_tool found")
-
# Never cache a design view.
req = getattr(self, "REQUEST", None)
if req is not None:
req["RESPONSE"].setHeader("Cache-Control", "no-cache")
-
- ui_obj = guarded_getattr(tool.uis, ui)
+ ui_obj = self.getUI(ui)
self._v_editing = 1
try:
return ui_obj.render(self)
@@ -178,13 +174,18 @@
"""
return self.design("zmi")
- security.declareProtected(perm_names.view, "isEditing")
- def isEditing(self):
- """Returns true if currently rendering in design mode.
+ security.declareProtected(perm_names.change_composites, "getUI")
+ def getUI(self, ui=None):
+ """Returns a UI object.
"""
- return self._v_editing
+ if not ui:
+ ui = self.default_ui
+ tool = aq_get(self, "composite_tool", None, 1)
+ if tool is None:
+ raise CompositeError("No composite_tool found")
+ return guarded_getattr(tool.uis, ui)
- security.declareProtected(perm_names.view, "getSlotNames")
+ security.declareProtected(perm_names.change_composites, "getSlotNames")
def getSlotNames(self):
"""Returns the names of the slots in order of use.
@@ -196,6 +197,30 @@
finally:
names = self.slots._endCollection()
return names
+
+ security.declareProtected(perm_names.change_composites, "getSlotData")
+ def getSlotData(self):
+ """Prepares information about slot contents for presentation.
+ """
+ contents = [] # [{name, slot_info}]
+ seen = {}
+ for name in names:
+ if seen.has_key(name):
+ # Don't show duplicate uses of a slot.
+ continue
+ seen[name] = 1
+ slot_info = {
+ 'title': name, # XXX need to get a real slot title somehow.
+ 'slot': composite.slots[name],
+ }
+ contents.append(slot_info)
+ return contents
+
+ security.declareProtected(perm_names.view, "isEditing")
+ def isEditing(self):
+ """Returns true if currently rendering in design mode.
+ """
+ return self._v_editing
Globals.InitializeClass(Composite)
=== Products/CompositePage/designuis.py 1.1.2.1 => 1.1.2.2 ===
--- Products/CompositePage/designuis.py:1.1.2.1 Fri Feb 20 11:59:46 2004
+++ Products/CompositePage/designuis.py Fri Feb 20 17:31:35 2004
@@ -32,6 +32,7 @@
_common = os.path.join(os.path.dirname(__file__), "common")
_zmi = os.path.join(os.path.dirname(__file__), "zmi")
_cmf = os.path.join(os.path.dirname(__file__), "cmf")
+_manual = os.path.join(os.path.dirname(__file__), "manual")
start_of_head_search = re.compile("(<head[^>]*>)", re.IGNORECASE).search
start_of_body_search = re.compile("(<body[^>]*>)", re.IGNORECASE).search
@@ -83,11 +84,10 @@
workspace_view_name = "" # To be overridden
- security.declarePrivate("render")
- def render(self, composite):
- """Renders a composite and adds scripts.
+ security.declarePublic("getFragments")
+ def getFragments(self, composite):
+ """Returns the fragments to be inserted in design mode.
"""
- text = composite()
params = {
"tool": aq_parent(aq_inner(self)),
"ui": self,
@@ -102,7 +102,15 @@
top += t.__of__(self)(**params)
for t in self.bottom_templates:
bottom += t.__of__(self)(**params)
-
+ return {"header": header, "top": top, "bottom": bottom}
+
+
+ security.declarePrivate("render")
+ def render(self, composite):
+ """Renders a composite, adding scripts and styles.
+ """
+ text = composite()
+ fragments = self.getFragments(composite)
match = start_of_head_search(text)
if match is None:
# Turn it into a page.
@@ -110,16 +118,16 @@
match = start_of_head_search(text)
if match is None:
raise CompositeError("Could not find header")
- if header:
+ if fragments['header']:
index = match.end(0)
- text = "%s%s%s" % (text[:index], header, text[index:])
- if top:
+ text = "%s%s%s" % (text[:index], fragments['header'], text[index:])
+ if fragments['top']:
match = start_of_body_search(text)
if match is None:
raise CompositeError("No 'body' tag found")
index = match.end(0)
- text = "%s%s%s" % (text[:index], top, text[index:])
- if bottom:
+ text = "%s%s%s" % (text[:index], fragments['top'], text[index:])
+ if fragments['bottom']:
match = end_of_body_search(text)
if match is None:
raise CompositeError("No 'body' end tag found")
@@ -129,8 +137,7 @@
match = m
m = end_of_body_search(text, match.end(0))
index = match.start(0)
- text = "%s%s%s" % (text[:index], bottom, text[index:])
-
+ text = "%s%s%s" % (text[:index], fragments['bottom'], text[index:])
return text
@@ -263,17 +270,3 @@
) + CommonUI.bottom_templates
Globals.InitializeClass(CMFUI)
-
-
-class ManualUI (SimpleItem):
- """Page design UI based on a simple list of slots.
-
- Does not display the actual template.
- """
- security = ClassSecurityInfo()
-
- security.declarePrivate("render")
- def render(self, composite):
- return 'foo'
-
-Globals.InitializeClass(ManualUI)
More information about the Zope-CVS
mailing list