Changeset 3457 in products


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:
8 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/docs/HISTORY.txt

    r3447 r3457  
    11Changelog 
    22========= 
     3 
     44.3-dev (unreleased) 
     5---------------- 
     6 
     7* implemented Captcha Provider feature. 
     8* added ability to include other captcha plugins who provides ICaptchaProvider. 
    39 
    4104.2 - Apr 20, 2012 
  • 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) 
  • quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/configure.zcml

    r3428 r3457  
    2626 
    2727    <configure zcml:condition="installed plone.app.discussion"> 
     28 
     29        <utility 
     30            factory=".captcha.CaptchaProvider" 
     31            provides="quintagroup.plonecaptchas.interfaces.ICaptchaProvider" 
     32            name="plonecaptchas" 
     33            /> 
    2834 
    2935        <adapter 
  • quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/interfaces.py

    r3279 r3457  
    44if HAS_APP_DISCUSSION: 
    55    from zope.publisher.interfaces.browser import IDefaultBrowserLayer 
     6    from zope.interface import Interface, Attribute 
    67 
    78    class IQGDiscussionCaptchas(IDefaultBrowserLayer): 
     
    1011        """ 
    1112 
     13    try: 
     14        from plone.app.discussion.interfaces import ICaptchaProvider 
     15        ICaptchaProvider  # keep pyflakes quiet 
     16    except ImportError: 
     17        class ICaptchaProvider(Interface): 
     18            """ Captcha Provider 
     19            """ 
     20            widget_factory = Attribute("Chaptcha widget factory") 
     21 
    1222 
    1323class IQGPloneCaptchas(IDefaultPloneLayer): 
  • quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/meta.zcml

    r3270 r3457  
    66         can be used by plone.app.discussion to add a Captcha field to comment  
    77         forms. --> 
    8     <meta:provides feature="plone.app.discussion-captcha" /> 
     8 
     9    <configure zcml:condition="installed plone.app.discussion"> 
     10        <meta:provides feature="plone.app.discussion-captcha" /> 
     11        <meta:provides feature="plone.app.discussion-captcha-provider" /> 
     12    </configure> 
    913     
    1014</configure> 
  • quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/version.txt

    r3447 r3457  
    1 4.2 
     14.3-dev 
  • quintagroup.plonecaptchas/trunk/setup.py

    r3447 r3457  
    22import os 
    33 
    4 version = '4.2' 
     4version = '4.3-dev' 
    55 
    66setup(name='quintagroup.plonecaptchas', 
Note: See TracChangeset for help on using the changeset viewer.