source: products/quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/setuphandlers.py @ 3168

Last change on this file since 3168 was 3168, checked in by vmaksymiv, 8 years ago

pep8, pyflakes fixes

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[2711]1import logging
2from zope.component import queryMultiAdapter
3
4logger = logging.getLogger('quintagroup.pfg.captcha')
5
[2730]6captcha_fields = []
[2711]7
[3168]8
[2711]9def migrateToPackage(context):
10    """
[3168]11    Collect old Products.qPloneCaptchaFields fields (before types tool setup).
12    """
[2729]13    global captcha_fields
14    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
[2711]15        return
[2729]16
[2711]17    site = context.getSite()
[2729]18    plone_tools = queryMultiAdapter((site, site.REQUEST), name="plone_tools")
19    ptypes = plone_tools.types()
20    cftype = getattr(ptypes, 'CaptchaField', None)
21    if cftype and getattr(cftype, 'product', "") == "qPloneCaptchaField":
22        catalog = plone_tools.catalog()
23        captcha_fields = [(cf.id, cf.getObject().aq_parent) \
[3168]24                          for cf in catalog.search(
25                                {'portal_type': 'CaptchaField'})]
[2729]26        logger.info("Old Products.qPloneCaptchaField fields collected.")
[2711]27
[2729]28
29def afterTypesTool(context):
30    """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha fields
31    (after types tool setup).
32    """
[2733]33    global captcha_fields
34
[2729]35    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
36        return
37
[2733]38    while captcha_fields:
39        cf_id, form = captcha_fields.pop()
[2729]40        form.manage_delObjects(cf_id)
41        form.invokeFactory("CaptchaField", cf_id)
42        logger.info("Fixed CaptchaField in '%s'" % form.getId())
43    logger.info("Finish Captcha field fixing")
Note: See TracBrowser for help on using the repository browser.