Last change
on this file since 3168 was
3168,
checked in by vmaksymiv, 13 years ago
|
pep8, pyflakes fixes
|
-
Property svn:eol-style set to
native
|
File size:
1.0 KB
|
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 |
---|
[1] | 4 | |
---|
[3168] | 5 | from quintagroup.pfg.captcha.config import PLONE_VERSION |
---|
[2852] | 6 | |
---|
[3168] | 7 | |
---|
[1] | 8 | class CaptchaValidator: |
---|
| 9 | |
---|
| 10 | name = 'CaptchaValidator' |
---|
[2737] | 11 | title = "" |
---|
| 12 | description = "" |
---|
[1] | 13 | |
---|
| 14 | def __init__(self, name, title='', description=''): |
---|
| 15 | self.name = name |
---|
| 16 | self.title = title or name |
---|
| 17 | self.description = description |
---|
| 18 | |
---|
| 19 | def __call__(self, value, *args, **kwargs): |
---|
| 20 | |
---|
[3168] | 21 | form = kwargs.get('instance') |
---|
[1] | 22 | portal = getToolByName(form, 'portal_url').getPortalObject() |
---|
| 23 | result = portal.captcha_validator() |
---|
| 24 | if result.status == 'failure': |
---|
[3168] | 25 | return ("%(problem)s" % {'problem': result.errors['key'][0]}) |
---|
[1] | 26 | else: |
---|
| 27 | return 1 |
---|
| 28 | |
---|
[2852] | 29 | if PLONE_VERSION == 4: |
---|
| 30 | from zope.interface import classImplements |
---|
| 31 | classImplements(CaptchaValidator, IValidator) |
---|
| 32 | else: |
---|
| 33 | CaptchaValidator.__implements__ = (IValidator,) |
---|
| 34 | |
---|
[1] | 35 | validation.register(CaptchaValidator('isCaptchaCorrect')) |
---|
Note: See
TracBrowser
for help on using the repository browser.