source: products/qPloneComments/tags/2.3/skins/qplonecomments/2.1/validate_talkback.vpy @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 19 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.7 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='',require_email, email=''
9##title=validates a discussion entry
10##
11from Products.CMFCore.utils import getToolByName
12
13dtool = context.portal_discussion
14try:
15    content = context.parentsInThread()[0]
16except AttributeError:
17    content = context
18if not dtool.isDiscussionAllowedFor(content):
19    raise Exception, "Discussion not allowed."
20
21if not subject:
22    state.setError('subject', context.translate('Please submit a subject.', domain="plonecomments"), 'subject_required')
23
24if not body_text:
25    state.setError('body_text', context.translate('Please submit a body.', domain="plonecomments"), 'body_required')
26   
27if require_email != 'False':
28    if not (email and context.portal_registration.isValidEmail(email)):
29        state.setError('email', context.translate('Please submit email.', domain="plonecomments"), 'email_required')
30
31if hasattr(context, 'captcha_validator'):
32    context.captcha_validator()
33
34pp = getToolByName(context, 'portal_properties')
35isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
36if isForAnonymous:
37    pm = getToolByName(context, 'portal_membership')
38    isAnonym = pm.isAnonymousUser()
39    if isAnonym:
40        req = context.REQUEST
41        if not (req.form.has_key('Creator') and not req.form['Creator'] == ""):
42            state.setError('Creator', context.translate('Please enter your name.', domain="plonecomments"), 'name_required')
43
44if state.getErrors():
45    return state.set(status='failure', portal_status_message='Please correct the indicated errors.')
46else:
47    return state
Note: See TracBrowser for help on using the repository browser.