def is_deletable(self): """is object deletable? a publishable object is only deletable if it's not published it's not approved """ if not checkPermission('silva.ApproveSilvaContent', self): if self.is_published(): raise ContentError(_(u"Content is published."), self) if self.is_approved(): raise ContentError(_(u"Content is approved."), self)
def deleter(self): to_delete = [] container_ids = set(self.context.objectIds()) try: protected = self.context._reserved_names except: protected = () content = yield while content is not None: try: content.is_deletable() except ContentError as error: result = error else: content_id = content.getId() if (content_id in container_ids and content_id not in protected and aq_base(self.context) is aq_base(aq_parent(content))): to_delete.append((content_id, content)) result = content else: result = ContentError(_("Cannot delete content."), content) content = yield result # Event for identifier, content in to_delete: compatibilityCall('manage_beforeDelete', content, content, self.context) notify(ObjectWillBeRemovedEvent(content, self.context, identifier)) # Delete for identifier, content in to_delete: self.context._objects = tuple( [i for i in self.context._objects if i['id'] != identifier]) self.context._delOb(identifier) try: content._v__object_deleted__ = 1 except: pass # Event for identifier, content in to_delete: notify(ObjectRemovedEvent(content, self.context, identifier)) if to_delete: notifyContainerModified(self.context)
def renamer(self): any_renames = False data = yield while data is not None: content, to_identifier, to_title = data result = None # Rename identifier from_identifier = content.getId() if to_identifier is not None and from_identifier != to_identifier: result = self.__verify_moveable(content) if result is None: try: ISilvaNameChooser(self.context).checkName( to_identifier, content) except ContentError as e: result = ContainerError(reason=e.reason, content=content) if result is None: content = self.__move(content, self.context, from_identifier, to_identifier) any_renames = True # Update title if to_title is not None: if not isinstance(to_title, str): to_title = to_title.decode('utf-8') editable = content.get_editable() if editable is None: if result is None: result = ContentError( _("There is no editable version to set the title on." ), content) elif editable.get_title() != to_title: try: editable.set_title(to_title) except ContentError as error: result = error if result is None: result = content data = yield result if any_renames: notifyContainerModified(self.context)
def checkName(self, identifier, content, file=None, interface=None): try: checkValidId(self.container, str(identifier)) except BadRequest as error: raise ContentError(error.args[0], self.container) return True
def verify(self): status = self.validate() if status != self.OK: return ContentError(self._status_to_string(status), self._context) return None
def to_publication(self): """Don't do anything here. Can't do this with root. """ raise ContentError(_("Root cannot be converted to publication."), self)
def to_folder(self): """Don't do anything here. Can't do this with root. """ raise ContentError(_("Root cannot be converted to folder."), self)
def to_publication(self): raise ContentError( _("You cannot convert a publication into a publication."), self)
def to_folder(self): """Turn this folder into a folder. """ raise ContentError(_("You cannot convert a folder into a folder."), self)