def __call__(self): if self.request.get('form.buttons.remove'): # Made form CSRF save if not self.request.method.lower() == 'post': raise Unauthorized self.remove_objects() msg = _(u'label_successfully_deleted', default=u'The documents have been successfully deleted') IStatusMessage(self.request).addStatusMessage(msg, type='info') return self.redirect_back() elif self.request.get('form.buttons.cancel'): return self.redirect_back() if not self.context.REQUEST.get('paths'): msg = _(u'error_no_documents_selected', default=u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.redirect_back() self.verify_documents() return super(RemoveConfirmation, self).__call__()
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) if not api.user.has_permission( 'opengever.trash: Untrash content', obj=obj): msg = _(u'Untrashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue trasher = ITrashable(obj) trasher.untrash() return self.request.RESPONSE.redirect( '%s#documents' % (self.context.absolute_url())) else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('%s#trash' % self.context.absolute_url())
def __call__(self): paths = self.request.get('paths') catalog = getToolByName(self.context, 'portal_catalog') trashed = False if paths: for item in paths: obj = self.context.restrictedTraverse(item) brains = catalog(path=item) # check that the object isn't already trashed if not brains: msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue # check that the document isn't checked_out if brains[0].checked_out: msg = _( u'could not trash the object ${obj}, it is checked out.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue if not api.user.has_permission( 'opengever.trash: Trash content', obj=obj): msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') continue trasher = ITrashable(obj) trasher.trash() trashed = True msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('{}#documents'.format( self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') catalog = getToolByName(self.context, 'portal_catalog') trashed = False if paths: for item in paths: obj = self.context.restrictedTraverse(item) brains = catalog(path=item) # check that the object isn't already trashed if not brains: msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') continue # check that the document isn't checked_out if brains[0].checked_out: msg = _( u'could not trash the object ${obj}, it is checked out', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') continue trasher = ITrashable(obj) trasher.trash() trashed = True msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='info') else: msg = _(u'You have not selected any items') IStatusMessage(self.request).addStatusMessage( msg, type='error') if trashed: return self.request.RESPONSE.redirect( '%s#trash' % self.context.absolute_url()) else: return self.request.RESPONSE.redirect( '%s#documents' % self.context.absolute_url())
def verify_no_relations(self): related_documents = self.document.related_items() objs_with_backreferences = self.get_backreferences() if related_documents: self.error_msg.append( _(u'msg_document_has_relations', default=u'The document contains relations.')) if objs_with_backreferences: links = [] for obj in objs_with_backreferences: links.append(u'<a href={}>{}</a>'.format( obj.absolute_url(), obj.title)) self.error_msg.append( _(u'msg_document_has_backreferences', default=u'The document is referred by the document(s) ${links}.', mapping={'links': ', '.join(links)}))
def verify_no_relations(self): related_documents = self.document.related_items() objs_with_backreferences = self.get_backreferences() if related_documents: self.error_msg.append( _(u'msg_document_has_relations', default=u'The document contains relations.')) if objs_with_backreferences: links = [] for obj in objs_with_backreferences: type_str = translate(obj.portal_type, 'opengever.core', context=getRequest()) links.append(u'<a href={}>{}: {}</a>'.format( obj.absolute_url(), type_str, obj.title)) self.error_msg.append( _(u'msg_document_has_backreferences', default=u'The document is referred by ${links}.', mapping={'links': ', '.join(links)}))
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'Document checked out': msg = _( u'could not trash the object ${obj}, it is checked' ' out.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') except Unauthorized: msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') else: msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage( msg, type='error') return self.request.RESPONSE.redirect( '{}#documents'.format(self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.trash() except TrashError as exc: if exc.message == 'Already trashed': msg = _( u'could not trash the object ${obj}, ' 'it is already trashed', mapping={'obj': obj.Title().decode('utf-8')}) elif exc.message == 'Document checked out': msg = _( u'could not trash the object ${obj}, it is checked' ' out.', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') except Unauthorized: msg = _(u'Trashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') else: msg = _(u'the object ${obj} trashed', mapping={'obj': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='info') else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('{}#documents'.format( self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.untrash() except Unauthorized: msg = _(u'Untrashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect( '%s#documents' % (self.context.absolute_url())) else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage(msg, type='error') return self.request.RESPONSE.redirect('%s#trash' % self.context.absolute_url())
def __call__(self): paths = self.request.get("paths") catalog = getToolByName(self.context, "portal_catalog") trashed = False if paths: for item in paths: obj = self.context.restrictedTraverse(item) brains = catalog(path=item) # check that the object isn't already trashed if not brains: msg = _( u"could not trash the object ${obj}, " "it is already trashed", mapping={"obj": obj.Title().decode("utf-8")}, ) IStatusMessage(self.request).addStatusMessage(msg, type="error") continue # check that the document isn't checked_out if brains[0].checked_out: msg = _( u"could not trash the object ${obj}, it is checked out", mapping={"obj": obj.Title().decode("utf-8")}, ) IStatusMessage(self.request).addStatusMessage(msg, type="error") continue trasher = ITrashable(obj) trasher.trash() trashed = True msg = _(u"the object ${obj} trashed", mapping={"obj": obj.Title().decode("utf-8")}) IStatusMessage(self.request).addStatusMessage(msg, type="info") else: msg = _(u"You have not selected any items") IStatusMessage(self.request).addStatusMessage(msg, type="error") return self.request.RESPONSE.redirect("{}#documents".format(self.context.absolute_url()))
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) try: trasher.untrash() except Unauthorized: msg = _(u'Untrashing ${title} is forbidden', mapping={'title': obj.Title().decode('utf-8')}) IStatusMessage(self.request).addStatusMessage( msg, type='error') return self.request.RESPONSE.redirect('%s#documents' % ( self.context.absolute_url())) else: msg = _(u'You have not selected any items.') IStatusMessage(self.request).addStatusMessage( msg, type='error') return self.request.RESPONSE.redirect( '%s#trash' % self.context.absolute_url())
def __call__(self): paths = self.request.get("paths") if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) trasher.untrash() return self.request.RESPONSE.redirect("%s#documents" % (self.context.absolute_url())) else: msg = _(u"You have not selected any items") IStatusMessage(self.request).addStatusMessage(msg, type="error") return self.request.RESPONSE.redirect("%s#trash" % self.context.absolute_url())
def __call__(self): paths = self.request.get('paths') if paths: for item in paths: obj = self.context.restrictedTraverse(item) trasher = ITrashable(obj) trasher.untrash() return self.request.RESPONSE.redirect('%s#documents' % ( self.context.absolute_url())) else: msg = _(u'You have not selected any items') IStatusMessage(self.request).addStatusMessage( msg, type='error') return self.request.RESPONSE.redirect( '%s#trash' % self.context.absolute_url())
def verify_is_trashed(self): if not ITrashed.providedBy(self.document): self.error_msg.append( _(u'msg_is_not_trashed', default=u'The document is not trashed.'))
def verify_checked_in(self): if self.document.is_checked_out(): self.error_msg.append( _(u'msg_document_is_checked_out', default=u'The document is still checked out.'))
def verify_is_not_removed(self): if self.document.is_removed: self.error_msg.append( _(u'msg_is_removed', default=u'The document is already removed.'))