1 | ## Controller Script Python "validate_talkback" |
---|
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=subject='',body_text='' |
---|
9 | ##title=validates a discussion entry |
---|
10 | ## |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | |
---|
13 | dtool = context.portal_discussion |
---|
14 | try: |
---|
15 | content = context.parentsInThread()[0] |
---|
16 | except AttributeError: |
---|
17 | content = context |
---|
18 | if not dtool.isDiscussionAllowedFor(content): |
---|
19 | raise Exception, "Discussion not allowed." |
---|
20 | |
---|
21 | if not subject: |
---|
22 | state.setError('subject', 'Please submit a subject.', 'subject_required') |
---|
23 | |
---|
24 | if not body_text: |
---|
25 | state.setError('body_text', 'Please submit a body.', 'body_required') |
---|
26 | |
---|
27 | pp = getToolByName(context, 'portal_properties') |
---|
28 | isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) |
---|
29 | if isForAnonymous: |
---|
30 | pm = getToolByName(context, 'portal_membership') |
---|
31 | isAnonym = pm.isAnonymousUser() |
---|
32 | if isAnonym: |
---|
33 | req = context.REQUEST |
---|
34 | if not (req.form.has_key('Creator') and not req.form['Creator'] == ""): |
---|
35 | state.setError('Creator', 'Please enter your Name.', 'name_required') |
---|
36 | |
---|
37 | if state.getErrors(): |
---|
38 | return state.set(status='failure', portal_status_message='Please correct the indicated errors.') |
---|
39 | else: |
---|
40 | return state |
---|