source: products/quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/validator.py @ 2852

Last change on this file since 2852 was 2852, checked in by mylan, 9 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
Line 
1from Products.CMFCore.utils import getToolByName
2from Products.validation import validation
3from Products.validation.interfaces.IValidator import IValidator
4from Products.CMFPlone.utils import safe_hasattr
5
6from config import PLONE_VERSION
7
8class CaptchaValidator:
9
10    name = 'CaptchaValidator'
11    title = ""
12    description = ""
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
29if PLONE_VERSION == 4:
30    from zope.interface import classImplements
31    classImplements(CaptchaValidator, IValidator)
32else:
33    CaptchaValidator.__implements__ = (IValidator,)
34
35validation.register(CaptchaValidator('isCaptchaCorrect'))
Note: See TracBrowser for help on using the repository browser.