[797] | 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 |
---|
[1871] | 12 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
[849] | 13 | |
---|
[797] | 14 | import string |
---|
| 15 | |
---|
| 16 | def 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 | |
---|
| 29 | form = context.REQUEST.form |
---|
| 30 | request_ids = form.keys() |
---|
| 31 | ct = form.get('static_captchas') |
---|
| 32 | skinstool = getToolByName(context, 'portal_skins') |
---|
| 33 | if ct == 'static': |
---|
| 34 | exchangeLayers('plone_captchas/dynamic', 'plone_captchas/static') |
---|
| 35 | else: |
---|
| 36 | exchangeLayers('plone_captchas/static', 'plone_captchas/dynamic') |
---|
| 37 | |
---|
| 38 | captcha_props = getToolByName(context, 'portal_properties')['qPloneCaptchas'] |
---|
| 39 | |
---|
| 40 | property_map=[(m['id'], m['type']) for m in captcha_props.propertyMap() if not m['id']=='title'] |
---|
| 41 | kw={} |
---|
| 42 | for 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 | |
---|
| 52 | captcha_props.manage_changeProperties(**kw) |
---|
| 53 | |
---|
[1871] | 54 | context.plone_utils.addPortalMessage(_(u'Changes saved.')) |
---|
[849] | 55 | return state |
---|