Last change
on this file since 2852 was
2852,
checked in by mylan, 14 years ago
|
#231: Fixed conflict with declaration of implemented interface for different plone versions
|
-
Property svn:eol-style set to
native
|
File size:
1.1 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 | from Products.CMFPlone.utils import safe_hasattr |
---|
| 5 | |
---|
[2852] | 6 | from config import PLONE_VERSION |
---|
| 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 | |
---|
| 21 | form = kwargs.get('instance') |
---|
| 22 | portal = getToolByName(form, 'portal_url').getPortalObject() |
---|
| 23 | result = portal.captcha_validator() |
---|
| 24 | if result.status == 'failure': |
---|
| 25 | return ("%(problem)s" % {'problem' : result.errors['key'][0]}) |
---|
| 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.