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

Last change on this file since 2737 was 2737, checked in by mylan, 14 years ago

Merged revisions 3750,3767-3774 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.pfg.captcha/branches/migration

........

r3750 | mylan | 2010-07-20 23:44:36 +0300 (Tue, 20 Jul 2010) | 1 line


#222: Added basic structure of migration Product to Package

........

r3767 | mylan | 2010-08-09 20:59:55 +0300 (Mon, 09 Aug 2010) | 1 line


Fix validator registration breakage

........

r3768 | mylan | 2010-08-09 21:07:08 +0300 (Mon, 09 Aug 2010) | 1 line


#222: Added migratioin old Products.qPloneCaptchaField to quintagroup.pfg.captcha fields

........

r3769 | mylan | 2010-08-10 12:19:58 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Fix typo

........

r3770 | mylan | 2010-08-10 12:59:59 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Move installation quintagroup.pfg.captcha with dependecies from global setupPloneSite to TestCase? classes

........

r3771 | mylan | 2010-08-10 14:09:48 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Splited tests.py module into 2 layers with notinstalled and installed quintagroup.pfg.captcha packages

........

r3772 | mylan | 2010-08-10 17:43:03 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Fix uninstallation 'old' packages when second run quintagroup.pfg.captcha installation

........

r3773 | mylan | 2010-08-10 17:43:54 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Added test for migration from old qPloneCaptchaField to new quintagroup.pfg.captcha

........

r3774 | mylan | 2010-08-10 18:03:41 +0300 (Tue, 10 Aug 2010) | 1 line


#222: Prepare to 1.0.1 release

........

  • 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
8def migrateToPackage(context):
[2729]9    """Collect old Products.qPloneCaptchaFields fields (before types tool setup).
[2711]10    """
[2729]11    global captcha_fields
12    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
[2711]13        return
[2729]14
[2711]15    site = context.getSite()
[2729]16    plone_tools = queryMultiAdapter((site, site.REQUEST), name="plone_tools")
17    ptypes = plone_tools.types()
18    cftype = getattr(ptypes, 'CaptchaField', None)
19    if cftype and getattr(cftype, 'product', "") == "qPloneCaptchaField":
20        catalog = plone_tools.catalog()
21        captcha_fields = [(cf.id, cf.getObject().aq_parent) \
22                          for cf in catalog.search({'portal_type':'CaptchaField'})]
23        logger.info("Old Products.qPloneCaptchaField fields collected.")
[2711]24
[2729]25
26def afterTypesTool(context):
27    """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha fields
28    (after types tool setup).
29    """
[2733]30    global captcha_fields
31
[2729]32    if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None:
33        return
34
[2733]35    while captcha_fields:
36        cf_id, form = captcha_fields.pop()
[2729]37        form.manage_delObjects(cf_id)
38        form.invokeFactory("CaptchaField", cf_id)
39        logger.info("Fixed CaptchaField in '%s'" % form.getId())
40    logger.info("Finish Captcha field fixing")
Note: See TracBrowser for help on using the repository browser.