1515e5eb93051fcb7255158f8e9fa71abec9a4f6
[Plinn.git] / skins / control / member_registration_modify.py
1 ## Script (Python) "member_registration_modify"
2 ##parameters=members=[], register=None, reject=None, ajax=''
3 ##title=Modify the status of a content object
4
5 from Products.CMFCore.utils import getToolByName
6 from ZTUtils import make_query as mq
7 req = context.REQUEST
8 resp = req.RESPONSE
9
10 utool = getToolByName(context, 'portal_url')
11 portal = utool.getPortalObject()
12 mtool = getToolByName(portal, 'portal_membership')
13
14 workflow_action = ''
15 wfkw = {}
16
17 if register :
18 members = [ mtool.getMemberById(entry['id']) for entry in members if entry.has_key('checked') ]
19 workflow_action = 'register'
20 nbMembers = len(members)
21 if not nbMembers :
22 message = 'Please select at least one member.'
23 elif nbMembers == 1 :
24 message = 'Member registered.'
25 else :
26 message = 'Members registered.'
27
28 elif reject :
29 # handle form from reject_member_form
30 members = [ mtool.getMemberById(entry['id']) for entry in members if entry.has_key('checked') ]
31 workflow_action = 'reject'
32 form = req.form
33 wfkw['subject'] = form.get('subject', '')
34 wfkw['body'] = form.get('body', '')
35 message = 'Registration rejected.'
36
37 else :
38 for m in members :
39 if m.has_key('reject') :
40 resp.redirect('%s/reject_member_form?%s' % ( portal.absolute_url(),
41 mq(id=m['id'], ajax=ajax) ))
42 return
43 raise ValueError, 'No action selected.'
44
45 wtool = getToolByName(portal, 'portal_workflow')
46
47 for m in members:
48 wtool.doActionFor(m, workflow_action, wf_id = 'member_workflow', **wfkw)
49
50
51
52 if ajax :
53 query = mq(portal_status_message=message, ajax='1', syncFragments=['rightCell'] )
54 else :
55 query = mq(portal_status_message=message)
56 redirect_url = portal.absolute_url() + '/pending_members?'+ query
57
58 resp.redirect( redirect_url )