source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/setuphandlers.py @ 964

Last change on this file since 964 was 964, checked in by crchemist, 13 years ago

Created dir for bundles.

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