def getUI(self, ui=None): """Returns a UI object. """ 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)
def __call__(self): """Renders the composite. """ if self._v_rendering: raise CompositeError("Circular composite reference") self._v_rendering = 1 try: template = self.getTemplate() return template(composite=self) finally: self._v_rendering = 0
def moveElements(self, source_paths, target_path, target_index, copy=0): """Moves or copies elements to a slot. """ target_index = int(target_index) # Coerce the paths to sequences of path elements. if hasattr(target_path, "split"): target_path = target_path.split('/') sources = [] for p in source_paths: if hasattr(p, "split"): p = p.split('/') if p: sources.append(p) # Ignore descendants when an ancestor is already listed. i = 1 sources.sort() while i < len(sources): prev = sources[i - 1] if sources[i][:len(prev)] == prev: del sources[i] else: i = i + 1 # Prevent parents from becoming their own descendants. for source in sources: if target_path[:len(source)] == source: raise CompositeError( "Can't make an object a descendant of itself") # Gather the sources, checking interfaces and security before # making any changes. root = self.getPhysicalRoot() elements = [] target = root.restrictedTraverse(target_path) assert ISlot.providedBy(target), repr(target) for source in sources: slot = root.restrictedTraverse(source[:-1]) assert ISlot.providedBy(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: if not copy: # Replace items with nulls to avoid changing indexes # while moving. for source in sources: slot = root.restrictedTraverse(source[:-1]) slot_id = id(aq_base(slot)) if not changed_slots.has_key(slot_id): changed_slots[slot_id] = slot # Check security nullify = guarded_getattr(slot, "nullify") nullify(source[-1]) # Add the elements and reorder. for element in elements: if not ICompositeElement.providedBy(element): # Make a composite element wrapper. element = CompositeElement(element.getId(), element) element = aq_base(element) new_id = target._get_id(element.getId()) if copy: element = copyOf(element) element._setId(new_id) target._setObject(new_id, element) # Check security reorder = guarded_getattr(target, "reorder") reorder(new_id, target_index) target_index += 1 finally: # Clear the nulls just added. for slot in changed_slots.values(): slot.pack()
def getTemplate(self): if not self.template_path: raise CompositeError("No template set") return self.restrictedTraverse(str(self.template_path))