source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/skins/plone_captchas/prefs_captchas_setup.cpy @ 1871

Last change on this file since 1871 was 1871, checked in by liebster, 14 years ago

Revert 2726 to 2589 commits for tagging plone-3 compatible version

File size: 1.6 KB
Line 
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##
11from Products.CMFCore.utils import getToolByName
12from Products.CMFPlone import PloneMessageFactory as _
13
14import string
15
16def exchangeLayers(layer1, layer2):
17    for skin in skinstool.getSkinSelections():
18        path = skinstool.getSkinPath(skin)
19        path = map( string.strip, string.split( path,',' ))
20        try:
21            i = path.index(layer1)
22            path.remove(layer1)
23            path.insert(i, layer2)
24        except ValueError:
25            pass
26        path = string.join( path, ', ' )
27        skinstool.addSkinSelection( skin, path )
28
29form = context.REQUEST.form
30request_ids = form.keys()
31ct = form.get('static_captchas')
32skinstool = getToolByName(context, 'portal_skins')
33if ct == 'static':
34    exchangeLayers('plone_captchas/dynamic', 'plone_captchas/static')
35else:
36    exchangeLayers('plone_captchas/static', 'plone_captchas/dynamic')
37
38captcha_props = getToolByName(context, 'portal_properties')['qPloneCaptchas']
39
40property_map=[(m['id'], m['type']) for m in captcha_props.propertyMap() if not m['id']=='title']
41kw={}
42for id,type in property_map:
43    if type == 'boolean':
44        if id in request_ids:
45            kw[id] = True
46        else:
47            kw[id] = False
48    else:
49        if id in request_ids:
50            kw[id] = form[id]
51
52captcha_props.manage_changeProperties(**kw)
53
54context.plone_utils.addPortalMessage(_(u'Changes saved.'))
55return state
Note: See TracBrowser for help on using the repository browser.