[Zope-CVS] CVS: Products/CompositePage - CHANGES.txt:1.1
slot.py:1.4 tool.py:1.3
Shane Hathaway
shane at zope.com
Wed Oct 8 10:51:12 EDT 2003
Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv6278
Modified Files:
slot.py tool.py
Added Files:
CHANGES.txt
Log Message:
Minor changes:
- The composite tool now checks copy/paste permissions before making
any changes.
- Slots now have a __str__ method, making it easy to render them
directly.
=== Added File Products/CompositePage/CHANGES.txt ===
Next version after 0.1
- You can now define slots in a template using standard METAL syntax.
This should make it easier to write templates.
- The composite tool now checks copy/paste permissions before making
any changes.
- Slots now have a __str__ method, making it easy to render them
directly.
=== Products/CompositePage/slot.py 1.3 => 1.4 ===
--- Products/CompositePage/slot.py:1.3 Wed Oct 1 16:59:52 2003
+++ Products/CompositePage/slot.py Wed Oct 8 10:51:12 2003
@@ -67,13 +67,25 @@
security.declareProtected(perm_names.view, "single")
def single(self):
- """Renders as a single-element slot."""
+ """Renders as a single-element slot.
+
+ Attempts to prevent the user from adding multiple elements
+ by not providing insertion points when the slot already
+ contains elements.
+ """
allow_add = (not self._objects)
return "".join(self.renderToList(allow_add))
security.declareProtected(perm_names.view, "multiple")
def multiple(self):
+ """Renders as a list containing multiple elements.
+ """
return self.renderToList(1)
+
+ def __str__(self):
+ """Renders as a string containing multiple elements.
+ """
+ return "".join(self.renderToList(1))
security.declareProtected(perm_names.change_composites, "reorder")
def reorder(self, name, new_index):
=== Products/CompositePage/tool.py 1.2 => 1.3 ===
--- Products/CompositePage/tool.py:1.2 Wed Oct 1 14:59:31 2003
+++ Products/CompositePage/tool.py Wed Oct 8 10:51:12 2003
@@ -99,37 +99,42 @@
raise CompositeError(
"Can't make an object a descendant of itself")
- # Gather the sources, replacing with nulls to avoid changing
- # indexes while moving.
+ # Gather the sources, checking interfaces and security before
+ # making any changes.
root = self.getPhysicalRoot()
- orig_slots = {} # id(aq_base(slot)) -> slot
elements = []
+ target = root.restrictedTraverse(target_path)
+ assert ISlot.isImplementedBy(target), repr(target)
+ for source in sources:
+ slot = root.restrictedTraverse(source[:-1])
+ assert ISlot.isImplementedBy(slot), repr(slot)
+ element = slot.restrictedTraverse(source[-1])
+ elements.append(element)
+ if self._check_security:
+ target._verifyObjectPaste(element)
+
+ changed_slots = {} # id(aq_base(slot)) -> slot
try:
+ # Replace items with nulls to avoid changing indexes while moving.
for source in sources:
slot = root.restrictedTraverse(source[:-1])
- assert ISlot.isImplementedBy(slot), repr(slot)
slot_id = id(aq_base(slot))
- if not orig_slots.has_key(slot_id):
- orig_slots[slot_id] = slot
+ if not changed_slots.has_key(slot_id):
+ changed_slots[slot_id] = slot
nullify = guarded_getattr(slot, "nullify") # Check security
- element = nullify(source[-1])
- elements.append(element)
+ nullify(source[-1])
# Add the elements and reorder.
- slot = root.restrictedTraverse(target_path)
- assert ISlot.isImplementedBy(slot), repr(slot)
for element in elements:
- if self._check_security:
- slot._verifyObjectPaste(element) # Check security
- new_id = slot._get_id(element.getId())
+ new_id = target._get_id(element.getId())
element._setId(new_id)
- slot._setObject(new_id, element)
- reorder = guarded_getattr(slot, "reorder") # Check security
+ target._setObject(new_id, element)
+ reorder = guarded_getattr(target, "reorder") # Check security
reorder(new_id, target_index)
target_index += 1
finally:
# Clear the nulls just added.
- for slot in orig_slots.values():
+ for slot in changed_slots.values():
slot.pack()
More information about the Zope-CVS
mailing list