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

Last change on this file since 3606 was 3606, checked in by vmaksymiv, 11 years ago

PPP fixes

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1import logging
2from zope.component import queryMultiAdapter
3
4logger = logging.getLogger('quintagroup.pfg.captcha')
5
6captcha_fields = []
7
8
9def migrateToPackage(context):
10    """
11    Collect old Products.qPloneCaptchaFields fields (before types tool setup).
12    """
13    global captcha_fields
14    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
15        return
16
17    site = context.getSite()
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)
24                          for cf in catalog.search(
25                          {'portal_type': 'CaptchaField'})]
26        logger.info("Old Products.qPloneCaptchaField fields collected.")
27
28
29def afterTypesTool(context):
30    """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha fields
31    (after types tool setup).
32    """
33    global captcha_fields
34
35    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
36        return
37
38    while captcha_fields:
39        cf_id, form = captcha_fields.pop()
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.