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 | student_id = context.getStudentId()
|
---|
30 | if ids:
|
---|
31 | sid_level = "%s|%s" % (student_id,context.getId())
|
---|
32 | for key in ['%s|%s' % (sid_level,id) for id in ids]:
|
---|
33 | context.course_results.deleteRecord(key)
|
---|
34 | logger.info('%s deleted CourseResults %s for %s' % (member,ids,student_id))
|
---|
35 | message = 'psm_item(s)_deleted'
|
---|
36 | else:
|
---|
37 | message = 'psm_select_at_least_one_document'
|
---|
38 |
|
---|
39 | args = {}
|
---|
40 | args['portal_status_message'] = message
|
---|
41 |
|
---|
42 | if action_after_validate:
|
---|
43 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
44 | else:
|
---|
45 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
46 | if REQUEST is not None:
|
---|
47 | return REQUEST.RESPONSE.redirect(url)
|
---|