1 | ## Script (Python) "prefs_recent_comments_delete" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | from Products.qPloneComments.utils import manage_mails |
---|
12 | from Products.qPloneComments.utils import setStatusMsg |
---|
13 | from Products.CMFPlone import MessageFactory |
---|
14 | _ = MessageFactory('plonecomments') |
---|
15 | |
---|
16 | portal_discussion = getToolByName(context, "portal_discussion") |
---|
17 | portal_catalog = getToolByName(context, "portal_catalog") |
---|
18 | |
---|
19 | request = context.REQUEST |
---|
20 | comment_ids = request.get('ids', []) |
---|
21 | |
---|
22 | for comment_id in comment_ids: |
---|
23 | comment = portal_catalog(id=comment_id,portal_type='Discussion Item')[0].getObject() |
---|
24 | |
---|
25 | parent = comment.inReplyTo() |
---|
26 | if parent is not None: |
---|
27 | talkback = portal_discussion.getDiscussionFor(parent) |
---|
28 | else: |
---|
29 | talkback = parent = comment.aq_parent |
---|
30 | |
---|
31 | comment = portal_catalog(id=comment_id,portal_type='Discussion Item')[0].getObject() |
---|
32 | talkback.deleteReply(comment_id) |
---|
33 | manage_mails(comment, context, 'deleting') |
---|
34 | |
---|
35 | msg = comment_ids and _(u'Comment(s) deleted.') or _(u'Please select items to be processed.') |
---|
36 | setStatusMsg(state, context, msg) |
---|
37 | |
---|
38 | return state |
---|