Changeset 2729 in products for quintagroup.pfg.captcha/branches/migration/quintagroup/pfg/captcha/setuphandlers.py
- Timestamp:
- Aug 9, 2010 6:07:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.pfg.captcha/branches/migration/quintagroup/pfg/captcha/setuphandlers.py
r2711 r2729 2 2 from zope.component import queryMultiAdapter 3 3 4 from quintagroup.canonicalpath.interfaces import ICanonicalLink5 from quintagroup.canonicalpath.adapters import PROPERTY_LINK6 7 4 logger = logging.getLogger('quintagroup.pfg.captcha') 8 5 9 def isNeedMigration(plone_tools): 6 capcha_fields = [] 7 8 def migrateToPackage(context): 9 """Collect old Products.qPloneCaptchaFields fields (before types tool setup). 10 """ 11 global captcha_fields 12 if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None: 13 return 14 15 site = context.getSite() 16 plone_tools = queryMultiAdapter((site, site.REQUEST), name="plone_tools") 10 17 ptypes = plone_tools.types() 11 18 cftype = getattr(ptypes, 'CaptchaField', None) 12 return cftype and getattr(cftype, 'product', "") == "qPloneCaptchaField" 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.") 13 24 14 def migrateToPackage(context): 15 """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha ob. 25 26 def afterTypesTool(context): 27 """ Replace old qPloneCaptchaField with new quintagroup.pfg.captcha fields 28 (after types tool setup). 16 29 """ 17 if context.readDataFile(' _uninstall.txt') is None:30 if context.readDataFile('quintagroup.pfg.captcha_default.txt') is None: 18 31 return 19 site = context.getSite()20 plone_tools = queryMultiAdapter((site, setuptool.REQUEST), name="plone_tools")21 32 22 if isNeedMigration(plone_tools): 23 pass 24 ## Find old objects: 25 #for cf in catalog.search({'portal_type':'CaptchaField'}): 26 # get parent obj, del old CaptchaField and create new one 27 # Then remove old portal type "CaptchaField" 28 # for path in plone_tools.catalog().search() 29 # recriateCaptchaFields(plone_tools) 30 # removeOldPortalType(plone_tools) 33 for cf_id, form in captcha_fields: 34 form.manage_delObjects(cf_id) 35 form.invokeFactory("CaptchaField", cf_id) 36 logger.info("Fixed CaptchaField in '%s'" % form.getId()) 37 logger.info("Finish Captcha field fixing")
Note: See TracChangeset
for help on using the changeset viewer.