[1] | 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='', email='', require_email |
---|
| 9 | ##title=validates a discussion entry |
---|
| 10 | ## |
---|
| 11 | from Products.CMFCore.utils import getToolByName |
---|
| 12 | |
---|
| 13 | if not subject: |
---|
| 14 | state.setError('subject', 'Please submit a subject.', 'subject_required') |
---|
| 15 | |
---|
| 16 | if not body_text: |
---|
| 17 | state.setError('body_text', 'Please submit a body.', 'body_required') |
---|
| 18 | |
---|
| 19 | if require_email != 'False': |
---|
| 20 | if not (email and context.portal_registration.isValidEmail(email)): |
---|
| 21 | state.setError('email', 'Please submit email.', 'email_required') |
---|
| 22 | |
---|
| 23 | if hasattr(context, 'captcha_validator'): |
---|
| 24 | context.captcha_validator() |
---|
| 25 | |
---|
| 26 | pp = getToolByName(context, 'portal_properties') |
---|
| 27 | isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) |
---|
| 28 | if isForAnonymous: |
---|
| 29 | pm = getToolByName(context, 'portal_membership') |
---|
| 30 | isAnonym = pm.isAnonymousUser() |
---|
| 31 | if isAnonym: |
---|
| 32 | req = context.REQUEST |
---|
| 33 | if not (req.form.has_key('Creator') and not req.form['Creator'] == ""): |
---|
| 34 | state.setError('Creator', 'Please enter your name.', 'name_required') |
---|
| 35 | |
---|
| 36 | if state.getErrors(): |
---|
| 37 | return state.set(status='failure', portal_status_message='Please correct the indicated errors.') |
---|
| 38 | else: |
---|
| 39 | return state |
---|