remove SimpleFieldValidator import fallback, because it breaks the CaptchaValidator.

svn path=/plone.app.discussion/trunk/; revision=28789
This commit is contained in:
Timo Stollenwerk 2009-08-13 18:53:27 +00:00
parent c3a0631813
commit ce30a1b594

View File

@ -27,21 +27,14 @@ try:
from plone.formwidget.captcha.validator import CaptchaValidator from plone.formwidget.captcha.validator import CaptchaValidator
HAS_CAPTCHA = True HAS_CAPTCHA = True
except ImportError: except ImportError:
# Fall back to SimpleFieldValidator, when Captcha is not installed, pass
# since otherwise the registration of the Captcha validator adapter
# would fail.
from z3c.form.validator import SimpleFieldValidator as CaptchaValidator
HAS_RECAPTCHA = False HAS_RECAPTCHA = False
try: try:
from plone.formwidget.recaptcha import ReCaptchaFieldWidget from plone.formwidget.recaptcha import ReCaptchaFieldWidget
HAS_RECAPTCHA = True HAS_RECAPTCHA = True
except ImportError: except ImportError:
# Fall back to SimpleFieldValidator, when ReCaptcha is not installed, pass
# since otherwise the registration of the ReCaptcha validator adapter
# would fail.
from z3c.form.validator import SimpleFieldValidator as CaptchaValidator
class Captcha(Persistent): class Captcha(Persistent):
interface.implements(ICaptcha) interface.implements(ICaptcha)
@ -51,6 +44,7 @@ class Captcha(Persistent):
Captcha = factory(Captcha) Captcha = factory(Captcha)
if HAS_CAPTCHA or HAS_RECAPTCHA: if HAS_CAPTCHA or HAS_RECAPTCHA:
# Extend the comment form with captcha, only if a captcha solution is installed. # Extend the comment form with captcha, only if a captcha solution is installed.
class CaptchaExtender(extensible.FormExtender): class CaptchaExtender(extensible.FormExtender):
adapts(Interface, IDefaultBrowserLayer, CommentForm) # context, request, form adapts(Interface, IDefaultBrowserLayer, CommentForm) # context, request, form
@ -78,9 +72,6 @@ if HAS_CAPTCHA or HAS_RECAPTCHA:
# If ReCaptcha is installed and ReCaptcha is enabled, # If ReCaptcha is installed and ReCaptcha is enabled,
# use the ReCaptchaFieldWidget # use the ReCaptchaFieldWidget
self.form.fields['captcha'].widgetFactory = ReCaptchaFieldWidget self.form.fields['captcha'].widgetFactory = ReCaptchaFieldWidget
else:
#
pass
# Register Captcha validator for the captcha field in the ICaptchaForm # Register Captcha validator for the captcha field in the ICaptchaForm
validator.WidgetValidatorDiscriminators(CaptchaValidator, field=ICaptcha['captcha']) validator.WidgetValidatorDiscriminators(CaptchaValidator, field=ICaptcha['captcha'])