Ignore:
Timestamp:
Apr 26, 2012 12:21:41 PM (12 years ago)
Author:
vmaksymiv
Message:

merged with captcha_provider branch

Location:
quintagroup.plonecaptchas/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecaptchas/trunk

    • Property svn:mergeinfo
      •  

        old new  
         1/quintagroup.plonecaptchas/branches/captcha_provider:3438-3456 
        12/quintagroup.plonecaptchas/branches/split2packs:1946-2024 
  • quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/captcha.py

    r3428 r3457  
    33from plone.app.discussion import vocabularies 
    44from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
    5 from z3c.form import interfaces 
    6 from quintagroup.plonecaptchas.config import CAPTCHA_NAME 
    75from quintagroup.plonecaptchas.interfaces import IQGDiscussionCaptchas 
     6from quintagroup.plonecaptchas.interfaces import ICaptchaProvider 
    87from zope.interface import Interface 
    9 from zope.component import adapts 
     8from zope.component import adapts, getUtilitiesFor, queryUtility 
    109from plone.app.discussion.browser.comments import CommentForm 
     10 
     11 
     12class CaptchaProvider(object): 
     13 
     14    def __init__(self): 
     15        self.widget_factory = CaptchaWidgetFactory 
    1116 
    1217 
     
    1621    def update(self): 
    1722        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: 
     23        if self.isAnon: 
     24            captcha_provider = queryUtility(ICaptchaProvider, 
     25                                            name=self.captcha) 
     26            if captcha_provider: 
     27                self.form.fields['captcha'].widgetFactory = \ 
     28                                                captcha_provider.widget_factory 
    2129                self.form.fields['captcha'].mode = None 
    2230 
     
    2533    """ Extend captcha vocabulary with quintagroup.plonecaptchas""" 
    2634    terms = vocabularies.captcha_vocabulary(context)._terms 
    27     terms.append(SimpleTerm(value=CAPTCHA_NAME, 
    28                             token=CAPTCHA_NAME, 
    29                             title=CAPTCHA_NAME)) 
     35    captchas = set((t.value for t in terms)) 
     36 
     37    providers = getUtilitiesFor(ICaptchaProvider) 
     38    for name, util in providers: 
     39        if name and name not in captchas: 
     40            terms.append(SimpleTerm(value=name, 
     41                                    token=name, 
     42                                    title=name.capitalize())) 
    3043    return SimpleVocabulary(terms) 
Note: See TracChangeset for help on using the changeset viewer.