source: products/qPloneComments/branches/plone3_extend/skins/qplonecomments/validate_talkback.vpy @ 858

Last change on this file since 858 was 806, checked in by crchemist, 17 years ago

Add role 'Editor' to portal.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
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
10from Products.CMFCore.utils import getToolByName
11from Products.CMFPlone import MessageFactory
12from Products.CMFPlone import PloneMessageFactory
13_ = MessageFactory('plonecomments')
14
15dtool = context.portal_discussion
16try:
17    content = context.parentsInThread()[0]
18except AttributeError:
19    content = context
20
21if not dtool.isDiscussionAllowedFor(content):
22    raise Exception, "Discussion not allowed."
23
24if not subject:
25    state.setError('subject', PloneMessageFactory(u'Please submit a subject.'), 'subject_required')
26
27if not body_text:
28    state.setError('body_text', PloneMessageFactory(u'Please submit a body.'), 'body_required')
29
30if require_email:
31    if not (email and context.portal_registration.isValidEmail(email)):
32        state.setError('email', _(u'Please submit email.'), 'email_required')
33
34if hasattr(context, 'captcha_validator'):
35    context.captcha_validator()
36
37pp = getToolByName(context, 'portal_properties')
38isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
39if isForAnonymous:
40    pm = getToolByName(context, 'portal_membership')
41    isAnonym = pm.isAnonymousUser()
42    if isAnonym:
43        req = context.REQUEST
44        if not (req.form.has_key('Creator') and not req.form['Creator'] == ""):
45            state.setError('Creator', _(u'Please enter your name.'), 'name_required')
46
47        try:
48            captcha_view = context.restrictedTraverse('@@captcha')
49            if not captcha_view.verify(captcha):
50                state.setError('captcha', _(u'You must correctly enter the word.'), 'captcha')
51        except:
52            # no collective.captcha installed
53            pass
54
55if state.getErrors():
56    context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
57    return state.set(status='failure')
58else:
59    return state
Note: See TracBrowser for help on using the repository browser.