source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/skins/quintagroup_plonecomments/prefs_comments_setup.cpy @ 2140

Last change on this file since 2140 was 2140, checked in by kroman0, 14 years ago

Added plone.browserlayer to requires

File size: 1.8 KB
Line 
1## Script (Python) "prefs_comments_setup"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10from Products.CMFCore.utils import getToolByName
11from quintagroup.plonecomments.utils import setAnonymCommenting, setStatusMsg
12from Products.CMFPlone import MessageFactory
13_ = MessageFactory('quintagroup.plonecomments')
14
15form = context.REQUEST.form
16pp = getToolByName(context, 'portal_properties')
17props_sheet = getattr(pp, 'qPloneComments')
18property_maps = [(m['id'], m['type'])
19                 for m in props_sheet.propertyMap()
20                 if not m['id']=='title']
21request_ids = form.keys()
22
23kw={}
24for id, type in property_maps:
25    if type == 'boolean':
26        if id in request_ids:
27            kw[id] = True
28        else:
29            kw[id] = False
30
31        # Switch anonymouse commenting
32        if id == 'enable_anonymous_commenting':
33            allow = False
34            if id in request_ids:
35                allow = True
36            setAnonymCommenting(context, allow)
37    else:
38        if id in request_ids:
39            kw[id] = form[id]
40
41props_sheet.manage_changeProperties(**kw)
42
43moderate_discussion = 'Moderate Discussion'
44if not 'EnableManagerModeration' in request_ids:
45    roles = [item['name'] for item in context.rolesOfPermission(moderate_discussion)
46             if (item['name'] != 'Manager') and (item['selected'] == 'SELECTED')]
47    context.manage_permission(moderate_discussion, roles,  acquire=0)
48
49else:
50    roles = [item['name'] for item in context.rolesOfPermission(moderate_discussion)
51             if item['selected'] == 'SELECTED']
52    roles.append('Manager')
53    context.manage_permission(moderate_discussion, roles,  acquire=0)
54
55setStatusMsg(state, context, _(u'qPloneComments configuration changes saved.'))
56return state
Note: See TracBrowser for help on using the repository browser.