source: trunk/skins/lemill/discussion_reply.cpy @ 1907

Revision 1907, 1.5 KB checked in by jukka, 12 years ago (diff)

Closed #1476, spent 20h. I'm allowing editing and deleting resource discussions like any other forum posts: if the discussion is deleted, new one will be created next time someone tries discussion. The default discussion post bodytext is i18n:translated, but once someone changes it, it won't try to translate it anymore.

Line 
1## Script (Python) "discussion_reply"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind state=state
7##bind subpath=traverse_subpath
8##parameters=body_text, origin
9##title=Reply to content
10
11from Products.PythonScripts.standard import url_quote_plus
12from Products.CMFCore.utils import getToolByName
13from Products.CMFPlone import PloneMessageFactory as PMF
14from Products.CMFPlone import transaction_note
15 
16mtool = getToolByName(context, 'portal_membership')
17dtool = getToolByName(context, 'portal_discussion')
18ltool = getToolByName(context, 'lemill_tool')
19req = context.REQUEST
20
21#body_text= ltool.render(body_text)
22
23creator = mtool.getAuthenticatedMember().getUserName()
24tb = dtool.getDiscussionFor(context)
25id = tb.createReply(title=body_text[:30], text=body_text, Creator=creator)
26reply = tb.getReply(id)
27
28# TODO THIS NEEDS TO GO AWAY!
29if hasattr(dtool.aq_explicit, 'cookReply'):
30    dtool.cookReply(reply, text_format='plain')
31
32parent = tb.aq_parent
33
34# return to the discussable object.
35anchor = reply.id
36
37if origin:
38    redirect_target = origin
39    target = '%s/discussion#%s' % (redirect_target, anchor)
40
41else:
42    redirect_target = context.plone_utils.getDiscussionThread(tb)[0]
43    view = redirect_target.getTypeInfo().getActionById('view')
44    target = '%s/%s#%s' % (redirect_target.absolute_url(), view, anchor)
45
46transaction_note('Added comment to %s at %s' % (parent.title_or_id(), reply.absolute_url()))
47
48msg = PMF(u'Comment added.')
49context.plone_utils.addPortalMessage(msg)
50
51
52return req.RESPONSE.redirect(target)
Note: See TracBrowser for help on using the repository browser.