From 18e92f7a8512d608affa7be98a7b552b0e3e39af Mon Sep 17 00:00:00 2001 From: Radim Novotny Date: Sat, 9 Oct 2010 11:13:28 +0000 Subject: [PATCH] - Fixed "global name 'WrongCaptchaCode' is not defined" if norobots captcha, but no other validation package is installed. svn path=/plone.app.discussion/trunk/; revision=40574 --- CHANGES.txt | 4 ++++ plone/app/discussion/browser/validator.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index a4c2a8f..30cc666 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Changelog 1.0b10 (unreleased) ------------------- +- Fixed "global name 'WrongCaptchaCode' is not defined" if norobots captcha, + but no other validation package is installed. + [naro] + - Check if there is a 'pending' review state in the current workflow for comments instead of just checking for the 'comment_review_workflow'. This allows integrators to use a custom review workflow. This fixes diff --git a/plone/app/discussion/browser/validator.py b/plone/app/discussion/browser/validator.py index 8a46bc7..8e38e6d 100644 --- a/plone/app/discussion/browser/validator.py +++ b/plone/app/discussion/browser/validator.py @@ -21,6 +21,11 @@ from plone.app.discussion.interfaces import ICaptcha from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionLayer +try: + from collective.z3cform.norobots.validator import WrongNorobotsAnswer +except ImportError: + pass + try: from plone.formwidget.captcha.validator import WrongCaptchaCode except ImportError: @@ -31,7 +36,6 @@ try: except ImportError: pass - class CaptchaValidator(validator.SimpleFieldValidator): implements(IValidator) adapts(Interface, IDiscussionLayer, Interface, IField, Interface) @@ -48,7 +52,10 @@ class CaptchaValidator(validator.SimpleFieldValidator): captcha = getMultiAdapter((aq_inner(self.context), self.request), name=settings.captcha) if not captcha.verify(input=value): - raise WrongCaptchaCode + if settings.captcha == 'norobots': + raise WrongNorobotsAnswer + else: + raise WrongCaptchaCode else: return True