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=message='', email='', require_email=False, comment_id=None |
---|
9 | ##title=validates a discussion entry |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | from Products.CMFPlone import MessageFactory |
---|
12 | from Products.CMFPlone import PloneMessageFactory |
---|
13 | _ = MessageFactory('quintagroup.plonecomments') |
---|
14 | |
---|
15 | try: |
---|
16 | content = context.parentsInThread()[0] |
---|
17 | except AttributeError: |
---|
18 | content = context |
---|
19 | |
---|
20 | pm = getToolByName(context, 'portal_membership') |
---|
21 | pp = getToolByName(context, 'portal_properties') |
---|
22 | if pm.isAnonymousUser(): |
---|
23 | if not pp.qPloneComments.getProperty('enable_anonymous_report_abuse'): |
---|
24 | raise Exception, "Abuse Report not allowed." |
---|
25 | else: |
---|
26 | if not pp.qPloneComments.getProperty('enable_authenticated_report_abuse'): |
---|
27 | raise Exception, "Abuse Report not allowed." |
---|
28 | |
---|
29 | if not message: |
---|
30 | state.setError('message', PloneMessageFactory(u'Please submit a message.'), 'message_required') |
---|
31 | |
---|
32 | if require_email: |
---|
33 | if not (email and context.portal_registration.isValidEmail(email)): |
---|
34 | state.setError('email', _(u'Please submit an email address.'), 'email_required') |
---|
35 | |
---|
36 | if hasattr(context, 'captcha_validator'): |
---|
37 | context.captcha_validator() |
---|
38 | |
---|
39 | isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) |
---|
40 | if isForAnonymous: |
---|
41 | pm = getToolByName(context, 'portal_membership') |
---|
42 | isAnonym = pm.isAnonymousUser() |
---|
43 | if isAnonym: |
---|
44 | req = context.REQUEST |
---|
45 | if not (req.form.has_key('creator') and not req.form['creator'] == ""): |
---|
46 | state.setError('creator', _(u'Please enter your name.'), 'name_required') |
---|
47 | |
---|
48 | try: |
---|
49 | captcha_view = context.restrictedTraverse('@@captcha') |
---|
50 | if not captcha_view.verify(captcha): |
---|
51 | state.setError('captcha', _(u'You must correctly enter the word.'), 'captcha') |
---|
52 | except: |
---|
53 | # no collective.captcha installed |
---|
54 | pass |
---|
55 | |
---|
56 | if state.getErrors(): |
---|
57 | context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.')) |
---|
58 | return state.set(status='failure') |
---|
59 | else: |
---|
60 | return state |
---|