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

Last change on this file since 3606 was 3168, checked in by vmaksymiv, 8 years ago

pep8, pyflakes fixes

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1from Products.CMFCore.utils import getToolByName
2from Products.validation import validation
3from Products.validation.interfaces.IValidator import IValidator
4
5from quintagroup.pfg.captcha.config import PLONE_VERSION
6
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.