Back to index

plone3  3.1.7
discussion_reply_form.py
Go to the documentation of this file.
00001 ##parameters=add='', edit='', preview=''
00002 ##
00003 from Products.PythonScripts.standard import structured_text
00004 from Products.CMFCore.utils import getToolByName
00005 from Products.CMFDefault.utils import decode
00006 from Products.CMFDefault.utils import html_marshal
00007 from Products.CMFDefault.utils import Message as _
00008 
00009 atool = getToolByName(script, 'portal_actions')
00010 
00011 
00012 form = context.REQUEST.form
00013 is_preview = False
00014 if add and \
00015         context.validateHTML(**form) and \
00016         context.discussion_reply(**form):
00017     return
00018 elif preview and \
00019         context.validateHTML(**form):
00020     is_preview = True
00021 
00022 
00023 options = {}
00024 
00025 title = form.get('title', context.Title())
00026 text = form.get('text', '')
00027 options['is_preview'] = is_preview
00028 options['title'] = title
00029 options['text'] = text
00030 options['cooked_text'] = structured_text(text)
00031 
00032 if is_preview:
00033     hidden_vars = [ {'name': n, 'value': v}
00034                     for n, v in html_marshal(title=title, text=text) ]
00035 else:
00036     hidden_vars = []
00037 buttons = []
00038 target = atool.getActionInfo('object/reply', context)['url']
00039 buttons.append( {'name': 'add', 'value': _(u'Add')} )
00040 if is_preview:
00041     buttons.append( {'name': 'edit', 'value': _(u'Edit')} )
00042 else:
00043     buttons.append( {'name': 'preview', 'value': _(u'Preview')} )
00044 options['form'] = { 'action': target,
00045                     'listHiddenVarInfos': tuple(hidden_vars),
00046                     'listButtonInfos': tuple(buttons) }
00047 
00048 return context.discussion_reply_template(**decode(options, script))