1 | ## Script (Python) "delete_course_result" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=ids=[], REQUEST=None, action_after_reject=None, action_after_validate='' |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: delete_course_result.py 1557 2007-03-15 16:00:27Z joachim $ |
---|
11 | """ |
---|
12 | FIXME: add docstring. |
---|
13 | """ |
---|
14 | |
---|
15 | from Products.CMFCore.utils import getToolByName |
---|
16 | from AccessControl import Unauthorized |
---|
17 | |
---|
18 | here = context |
---|
19 | from urllib import urlencode |
---|
20 | import logging |
---|
21 | logger = logging.getLogger('Skins.delete_course_result') |
---|
22 | mtool = context.portal_membership |
---|
23 | wf = context.portal_workflow |
---|
24 | member = mtool.getAuthenticatedMember() |
---|
25 | |
---|
26 | ret_url = here.absolute_url() |
---|
27 | |
---|
28 | message = '' |
---|
29 | if ids: |
---|
30 | real_ids = [] |
---|
31 | for id in ids: |
---|
32 | if context.hasObject(id): |
---|
33 | real_ids.append(id) |
---|
34 | for cr_id in real_ids: |
---|
35 | cr = getattr(context,cr_id) |
---|
36 | if wf.getInfoFor(cr,'review_state',None) == "closed": |
---|
37 | context.portal_workflow.doActionFor(cr,'open') |
---|
38 | if real_ids: |
---|
39 | try: |
---|
40 | context.manage_delObjects(real_ids) |
---|
41 | logger.info('%s deleted StudentCourseResult object %s for %s' % (member,id,context.getStudentId())) |
---|
42 | message = 'psm_item(s)_deleted' |
---|
43 | except Unauthorized: |
---|
44 | logger.info('%s has no permission to delete StudentCourseResult objects for %s' % (member,context.getStudentId())) |
---|
45 | message = 'no item(s) deleted' |
---|
46 | else: |
---|
47 | message = 'psm_select_at_least_one_document' |
---|
48 | |
---|
49 | args = {} |
---|
50 | args['portal_status_message'] = message |
---|
51 | |
---|
52 | if action_after_validate: |
---|
53 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
54 | else: |
---|
55 | url = context.absolute_url() + '?' + urlencode(args) |
---|
56 | if REQUEST is not None: |
---|
57 | return REQUEST.RESPONSE.redirect(url) |
---|