1 | from plone.app.discussion.browser.captcha import CaptchaExtender |
---|
2 | from quintagroup.z3cform.captcha.widget import CaptchaWidgetFactory |
---|
3 | from plone.app.discussion import vocabularies |
---|
4 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
5 | from z3c.form import interfaces |
---|
6 | from quintagroup.plonecaptchas.config import CAPTCHA_NAME |
---|
7 | from quintagroup.plonecaptchas.interfaces import IQGDiscussionCaptchas |
---|
8 | from zope.interface import Interface |
---|
9 | from zope.component import adapts |
---|
10 | from plone.app.discussion.browser.comments import CommentForm |
---|
11 | |
---|
12 | |
---|
13 | class 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 | |
---|
24 | def 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) |
---|