1 | ## Controller Script (Python) "prefs_captchas_setup" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind state=state |
---|
7 | ##bind subpath=traverse_subpath |
---|
8 | ##parameters= |
---|
9 | ##title=Set necessary skin |
---|
10 | ## |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | import string |
---|
13 | |
---|
14 | def exchangeLayers(layer1, layer2): |
---|
15 | for skin in skinstool.getSkinSelections(): |
---|
16 | path = skinstool.getSkinPath(skin) |
---|
17 | path = map( string.strip, string.split( path,',' )) |
---|
18 | try: |
---|
19 | i = path.index(layer1) |
---|
20 | path.remove(layer1) |
---|
21 | path.insert(i, layer2) |
---|
22 | except ValueError: |
---|
23 | pass |
---|
24 | path = string.join( path, ', ' ) |
---|
25 | skinstool.addSkinSelection( skin, path ) |
---|
26 | |
---|
27 | form = context.REQUEST.form |
---|
28 | request_ids = form.keys() |
---|
29 | ct = form.get('static_captchas') |
---|
30 | skinstool = getToolByName(context, 'portal_skins') |
---|
31 | if ct == 'static': |
---|
32 | exchangeLayers('plone_captchas/dynamic', 'plone_captchas/static') |
---|
33 | else: |
---|
34 | exchangeLayers('plone_captchas/static', 'plone_captchas/dynamic') |
---|
35 | |
---|
36 | captcha_props = getToolByName(context, 'portal_properties')['qPloneCaptchas'] |
---|
37 | |
---|
38 | property_map=[(m['id'], m['type']) for m in captcha_props.propertyMap() if not m['id']=='title'] |
---|
39 | kw={} |
---|
40 | for id,type in property_map: |
---|
41 | if type == 'boolean': |
---|
42 | print id |
---|
43 | if id in request_ids: |
---|
44 | kw[id] = True |
---|
45 | else: |
---|
46 | kw[id] = False |
---|
47 | else: |
---|
48 | if id in request_ids: |
---|
49 | kw[id] = form[id] |
---|
50 | |
---|
51 | captcha_props.manage_changeProperties(kw) |
---|
52 | |
---|
53 | return state.set(portal_status_message = 'Changes saved.') |
---|