| 1 | ## Script (Python) "getMembersDirectoryActions" |
|---|
| 2 | ##bind container=container |
|---|
| 3 | ##bind context=context |
|---|
| 4 | ##bind namespace= |
|---|
| 5 | ##bind script=script |
|---|
| 6 | ##bind subpath=traverse_subpath |
|---|
| 7 | ##parameters=mode |
|---|
| 8 | #$Id: getMembersDirectoryActions.py 2564 2007-11-07 10:50:54Z joachim $ |
|---|
| 9 | """ |
|---|
| 10 | Get the actions to provide on members directory view |
|---|
| 11 | |
|---|
| 12 | Return the updated actions |
|---|
| 13 | """ |
|---|
| 14 | try: |
|---|
| 15 | from Products.zdb import set_trace |
|---|
| 16 | except: |
|---|
| 17 | def set_trace(): |
|---|
| 18 | pass |
|---|
| 19 | if context.isStudent(): |
|---|
| 20 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
|---|
| 21 | |
|---|
| 22 | from Products.CMFCore.utils import getToolByName |
|---|
| 23 | request = context.REQUEST |
|---|
| 24 | qstring = request.get('QUERY_STRING','') |
|---|
| 25 | if qstring: |
|---|
| 26 | id = '' |
|---|
| 27 | for par in qstring.split('&'): |
|---|
| 28 | if par.startswith('id='): |
|---|
| 29 | id = par[3:] |
|---|
| 30 | else: |
|---|
| 31 | id = request.form.get('id','') |
|---|
| 32 | utool = getToolByName(context, 'portal_url') |
|---|
| 33 | dtool = getToolByName(context, 'portal_directories') |
|---|
| 34 | base_url = utool.getBaseUrl() |
|---|
| 35 | renderActionIcon = context.portal_cpsportlets.renderActionIcon |
|---|
| 36 | dirname = 'members' |
|---|
| 37 | dir = getattr(dtool,'members') |
|---|
| 38 | actions_list = (('create_action', |
|---|
| 39 | 'new_entry', |
|---|
| 40 | 'Create New Member', |
|---|
| 41 | base_url+'member_create_form?dirname=members', |
|---|
| 42 | ), |
|---|
| 43 | ('search_action', |
|---|
| 44 | 'search_entry', |
|---|
| 45 | 'Search Member', |
|---|
| 46 | base_url+'search_members_form?dirname=members', |
|---|
| 47 | ), |
|---|
| 48 | ('view_action', |
|---|
| 49 | 'view_entry', |
|---|
| 50 | 'View', |
|---|
| 51 | base_url+'member_view?dirname=members'+'&id='+id, |
|---|
| 52 | ), |
|---|
| 53 | ('edit_action', |
|---|
| 54 | 'edit_entry', |
|---|
| 55 | 'Edit', |
|---|
| 56 | base_url+'member_edit_form?dirname=members'+'&id='+id, |
|---|
| 57 | ), |
|---|
| 58 | ) |
|---|
| 59 | ad = {} |
|---|
| 60 | for action_id,name,desc,url in actions_list: |
|---|
| 61 | ad[action_id] = { |
|---|
| 62 | 'id': name, |
|---|
| 63 | 'title': desc, |
|---|
| 64 | 'icon_tag': renderActionIcon(action_id= name, |
|---|
| 65 | category='object', |
|---|
| 66 | base_url=base_url, |
|---|
| 67 | alt= name), |
|---|
| 68 | 'url': url, |
|---|
| 69 | 'name': desc, |
|---|
| 70 | 'category': 'object', |
|---|
| 71 | } |
|---|
| 72 | if not dtool.members.isSectionOfficer(): |
|---|
| 73 | return [ad['view_action'], |
|---|
| 74 | ad['edit_action'] |
|---|
| 75 | ] |
|---|
| 76 | |
|---|
| 77 | if mode in ['view', 'edit']: |
|---|
| 78 | return [ad['view_action'], |
|---|
| 79 | ad['edit_action'], |
|---|
| 80 | ad['create_action'], |
|---|
| 81 | ad['search_action'] |
|---|
| 82 | ] |
|---|
| 83 | elif mode in ['create']: |
|---|
| 84 | return [ad['search_action'],] |
|---|
| 85 | return [ad['create_action'],] |
|---|