Last change
on this file since 2728 was
2728,
checked in by mylan, 14 years ago
|
Fix validator registration breakage
|
-
Property svn:eol-style set to
native
|
File size:
939 bytes
|
Rev | Line | |
---|
[1] | 1 | from Products.CMFCore.utils import getToolByName |
---|
[2295] | 2 | from Products.validation import validation |
---|
| 3 | from Products.validation.interfaces.IValidator import IValidator |
---|
| 4 | from zope.interface import implements |
---|
[1] | 5 | |
---|
| 6 | from Products.CMFPlone.utils import safe_hasattr |
---|
| 7 | |
---|
| 8 | class CaptchaValidator: |
---|
| 9 | |
---|
[2728] | 10 | __implements__ = (IValidator,) |
---|
[1] | 11 | |
---|
| 12 | name = 'CaptchaValidator' |
---|
[2728] | 13 | title = "" |
---|
| 14 | description = "" |
---|
[1] | 15 | |
---|
| 16 | def __init__(self, name, title='', description=''): |
---|
| 17 | self.name = name |
---|
| 18 | self.title = title or name |
---|
| 19 | self.description = description |
---|
| 20 | |
---|
| 21 | def __call__(self, value, *args, **kwargs): |
---|
| 22 | |
---|
| 23 | form = kwargs.get('instance') |
---|
| 24 | portal = getToolByName(form, 'portal_url').getPortalObject() |
---|
| 25 | result = portal.captcha_validator() |
---|
| 26 | if result.status == 'failure': |
---|
| 27 | return ("%(problem)s" % {'problem' : result.errors['key'][0]}) |
---|
| 28 | else: |
---|
| 29 | return 1 |
---|
| 30 | |
---|
| 31 | validation.register(CaptchaValidator('isCaptchaCorrect')) |
---|
Note: See
TracBrowser
for help on using the repository browser.