source: products/quintagroup.captcha.core/trunk/quintagroup/captcha/core/setuphandlers.py @ 3128

Last change on this file since 3128 was 3128, checked in by vmaksymiv, 13 years ago

pep8 fixes

File size: 1.3 KB
Line 
1from random import randint
2
3from Products.CMFCore.utils import getToolByName
4
5from quintagroup.captcha.core.config import CAPTCHA_KEY, CONFIGLET_ID, \
6    ALL_LAYERS, PROPERTY_SHEET
7
8
9def generateKey(length):
10    key = ''
11    for i in range(length):
12        key += str(randint(0, 9))
13    return key
14
15
16def setupVarious(context):
17    if context.readDataFile('quintagroup.captcha.core_various.txt') is None:
18        return
19
20    site = context.getSite()
21
22    # set captcha key
23    value = generateKey(8)
24    if site.hasProperty(CAPTCHA_KEY):
25        site._updateProperty(CAPTCHA_KEY, value)
26    else:
27        site._setProperty(CAPTCHA_KEY, value, 'string')
28
29
30def uninstall(context):
31    # Only run step if a flag file is present (e.g. not an extension profile)
32    if context.readDataFile('quintagroup.captcha.core_uninstall.txt') is None:
33        return
34
35    site = context.getSite()
36
37    # remove configlet
38    cpt = getToolByName(site, 'portal_controlpanel')
39    if CONFIGLET_ID in [o.id for o in cpt.listActions()]:
40        cpt.unregisterConfiglet(CONFIGLET_ID)
41
42    # remove property sheet
43    pp = getToolByName(site, 'portal_properties')
44    if PROPERTY_SHEET in pp.objectIds():
45        pp.manage_delObjects(ids=[PROPERTY_SHEET])
46
47    # remove captcha key property
48    if site.hasProperty(CAPTCHA_KEY):
49        site._delProperty(CAPTCHA_KEY)
Note: See TracBrowser for help on using the repository browser.