source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/captcha.py @ 3428

Last change on this file since 3428 was 3428, checked in by vmaksymiv, 12 years ago

compatibility with plone.app.discussion added.(captcha_vocabulary utility overrides)

File size: 1.3 KB
Line 
1from plone.app.discussion.browser.captcha import CaptchaExtender
2from quintagroup.z3cform.captcha.widget import CaptchaWidgetFactory
3from plone.app.discussion import vocabularies
4from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
5from z3c.form import interfaces
6from quintagroup.plonecaptchas.config import CAPTCHA_NAME
7from quintagroup.plonecaptchas.interfaces import IQGDiscussionCaptchas
8from zope.interface import Interface
9from zope.component import adapts
10from plone.app.discussion.browser.comments import CommentForm
11
12
13class CaptchaExtender(CaptchaExtender):
14    adapts(Interface, IQGDiscussionCaptchas, CommentForm)
15
16    def update(self):
17        super(CaptchaExtender, self).update()
18        if self.captcha == CAPTCHA_NAME and self.isAnon:
19            self.form.fields['captcha'].widgetFactory = CaptchaWidgetFactory
20            if self.form.fields['captcha'].mode == interfaces.HIDDEN_MODE:
21                self.form.fields['captcha'].mode = None
22
23
24def captcha_vocabulary(context):
25    """ Extend captcha vocabulary with quintagroup.plonecaptchas"""
26    terms = vocabularies.captcha_vocabulary(context)._terms
27    terms.append(SimpleTerm(value=CAPTCHA_NAME,
28                            token=CAPTCHA_NAME,
29                            title=CAPTCHA_NAME))
30    return SimpleVocabulary(terms)
Note: See TracBrowser for help on using the repository browser.