def update(self): super(DeleteConfirmation, self).update() self.title = safe_unicode(self.context.title_or_id()) parent = self.context.aq_inner.aq_parent if ('form.button.Delete' not in self.request and 'form.button.Cancel' not in self.request): # ask for confirmation (don't redirect) return if 'form.button.Delete' in self.request: # check if the object has incoming relations: catalog = component.getUtility(ICatalog) intids = component.getUtility(IIntIds) relations = catalog.findRelations({ 'to_id': intids.getId(self.context)}) # remove relations for rel in relations: getattr(rel.from_object, 'relatedFiles', []).remove(rel) # delete parent.manage_delObjects(self.context.getId()) IStatusMessage(self.request).addStatusMessage( _(u'"%s" has been deleted.' % self.title), "info") workspace = parent while not IWorkspace.providedBy(workspace): workspace = workspace.aq_parent self.request.response.redirect( '/'.join([workspace.absolute_url(), 'conversation']))
def send_post_notifications(obj, event): if event.action != 'publish': return workspace = obj.aq_parent while not IWorkspace.providedBy(workspace): workspace = workspace.aq_parent messenger = IMessenger(workspace) recipients = workspace.getMemberIds() for uid in recipients: if messenger.getAttrForUid(uid, 'recieveNotifications', True): try: messenger.notifyAboutNewPost(uid, obj) except: pass
def send_reply_notifications(obj, event): workspace = obj.aq_parent while not IWorkspace.providedBy(workspace): workspace = workspace.aq_parent messenger = IMessenger(workspace) root = obj.aq_parent while IThreaded.providedBy(root.aq_parent): root = root.aq_parent catalog = getToolByName(obj, 'portal_catalog') replies = catalog({ 'object_provides': IThreaded.__identifier__, 'path': '/'.join(root.getPhysicalPath()), }) recipients = set([b.Creator for b in replies]) for uid in recipients: if messenger.getAttrForUid(uid, 'recieveNotifications', True): try: messenger.notifyAboutNewReply(uid, obj) except: pass
def updateWorkspaceIndex(obj, event): while not IWorkspace.providedBy(obj): obj = obj.aq_parent modified(obj)