1 | from random import randint |
---|
2 | |
---|
3 | from Products.CMFCore.utils import getToolByName |
---|
4 | |
---|
5 | from quintagroup.captcha.core.config import CAPTCHA_KEY, CONFIGLET_ID, \ |
---|
6 | ALL_LAYERS, PROPERTY_SHEET |
---|
7 | |
---|
8 | def generateKey(length): |
---|
9 | key = '' |
---|
10 | for i in range(length): |
---|
11 | key += str(randint(0, 9)) |
---|
12 | return key |
---|
13 | |
---|
14 | def setupVarious(context): |
---|
15 | if context.readDataFile('quintagroup.captcha.core_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 | |
---|
27 | def uninstall(context): |
---|
28 | # Only run step if a flag file is present (e.g. not an extension profile) |
---|
29 | if context.readDataFile('quintagroup.captcha.core_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]) |
---|
43 | |
---|
44 | # remove captcha key property |
---|
45 | if site.hasProperty(CAPTCHA_KEY): |
---|
46 | site._delProperty(CAPTCHA_KEY) |
---|