Changeset 7287


Ignore:
Timestamp:
6 Dec 2011, 16:07:02 (15 years ago)
Author:
uli
Message:
  • Fix interface.
  • Implement getCaptcha.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/captcha.py

    r7284 r7287  
    2424import urllib2
    2525from zope import schema
    26 from zope.component import getUtilitiesFor
     26from zope.component import getUtilitiesFor, getUtility, queryUtility
    2727from zope.interface import Interface
    2828from zope.publisher.interfaces.http import IHTTPRequest
    … …  
    9696    """A chooser that collects available captchas.
    9797    """
    98     def getAvailCaptchas(self):
     98    def getAvailCaptchas():
    9999        """Return a dict of available captchas with registered names as keys.
    100100        """
    101101
    102     def getCaptcha(self):
     102    def getCaptcha():
    103103        """Get captcha chosen for a certain site or default.
    104104        """
    105105
    106     def getConfigData(self, captcha):
     106    def getConfigData(captcha):
    107107        """Get a dict of config data for a certain captcha.
    108108        """
    109109
    110     def setConfigData(self, captcha, key, value):
     110    def setConfigData(captcha, key, value):
    111111        """Set a certain configuration key for a certain captcha.
    112112        """
    … …  
    130130        """
    131131        result = getUtilitiesFor(ICaptcha)
    132         return dict([x for x in result
    133                        if x != u''])
     132        return dict([(name,inst) for name,inst in result
     133                       if name != u''])
    134134
    135135    def getCaptcha(self):
     136        """Get captcha chosen to be used.
     137
     138        Sites can activate a specific captcha by setting
     139        ``site['configuration']['captcha']``. The value should be a
     140        string under which the specific captcha is registered.
     141
     142        If this value cannot be found (or is not set at all) or we are
     143        not 'in a site', the default captcha is returned.
     144        """
    136145        site = grok.getSite()
    137146        name = ''
    138147        if site is None:
    139             # return the default captcha, registered without name
    140148            return getUtility(ICaptcha)
    141149        name = site.get('configuration', None).get('captcha', u'')
    142         return getUtility(ICaptcha, name=name)
     150        return queryUtility(ICaptcha, name=name,
     151                            default=getUtility(ICaptcha))
    143152
    144153#
Note: See TracChangeset for help on using the changeset viewer.