Move the registration of the captcha validator from validator.py to the (demo) form. This is the only way to allow the creator of a form to register the captcha validator for a form without touching the p.f.c. code. This is somehow ugly. Maybe there is a more elegant way to do this?!
svn path=/plone.formwidget.captcha/trunk/; revision=28729
This commit is contained in:
parent
42c8e520d1
commit
a76a7f76a6
|
@ -40,11 +40,6 @@
|
|||
provides="Products.GenericSetup.interfaces.EXTENSION"
|
||||
/>
|
||||
|
||||
<!-- Validators -->
|
||||
<adapter
|
||||
factory=".validator.CaptchaValidator"
|
||||
/>
|
||||
|
||||
<!--
|
||||
example:
|
||||
http://yourplonesite/@@captcha_form
|
||||
|
|
|
@ -14,4 +14,9 @@
|
|||
provides=".form.ICaptchaForm"
|
||||
factory=".form.Captcha" />
|
||||
|
||||
<!-- Validators -->
|
||||
<adapter
|
||||
factory=".form.CaptchaValidator"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -2,9 +2,10 @@ from Acquisition import aq_inner
|
|||
|
||||
from zope import interface
|
||||
from zope import schema
|
||||
from zope.component import getMultiAdapter
|
||||
|
||||
from z3c.form import form, field, button
|
||||
from zope.component import getMultiAdapter, provideAdapter
|
||||
|
||||
from z3c.form import form, field, button, validator
|
||||
|
||||
from plone.z3cform.layout import wrap_form
|
||||
|
||||
|
@ -43,4 +44,7 @@ class BaseForm(form.Form):
|
|||
print data['subject']
|
||||
return
|
||||
|
||||
CaptchaForm = wrap_form(BaseForm)
|
||||
CaptchaForm = wrap_form(BaseForm)
|
||||
|
||||
# Register Captcha Validator for the captcha field in the ICaptchaForm
|
||||
validator.WidgetValidatorDiscriminators(CaptchaValidator, field=ICaptchaForm['captcha'])
|
|
@ -23,8 +23,4 @@ class CaptchaValidator(validator.SimpleFieldValidator):
|
|||
raise WrongCaptchaCode
|
||||
else:
|
||||
return True
|
||||
raise WrongCaptchaCode
|
||||
|
||||
from plone.formwidget.captcha.demo.form import ICaptchaForm
|
||||
validator.WidgetValidatorDiscriminators(CaptchaValidator, field=ICaptchaForm['captcha'])
|
||||
provideAdapter(CaptchaValidator)
|
||||
raise WrongCaptchaCode
|
Reference in New Issue