1 | ## Script (Python) "add_course_result"
|
---|
2 | ##bind container=container
|
---|
3 | ##bind context=context
|
---|
4 | ##bind namespace=
|
---|
5 | ##bind script=script
|
---|
6 | ##bind subpath=traverse_subpath
|
---|
7 | ##parameters=REQUEST=None, action_after_validate=''
|
---|
8 | ##title=
|
---|
9 | ##
|
---|
10 | # $Id: add_course_result.py 2451 2007-10-27 14:26:41Z joachim $
|
---|
11 | """
|
---|
12 | add a StudentCourseResult object
|
---|
13 | """
|
---|
14 |
|
---|
15 | import logging
|
---|
16 | logger = logging.getLogger('Skins.add_course_result')
|
---|
17 |
|
---|
18 | from urllib import urlencode
|
---|
19 | try:
|
---|
20 | from Products.zdb import set_trace
|
---|
21 | except:
|
---|
22 | def set_trace():
|
---|
23 | pass
|
---|
24 | request = context.REQUEST
|
---|
25 | course_cat = context.courses_catalog
|
---|
26 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
27 | try:
|
---|
28 | aq_portal = context.portal_catalog.evalAdvancedQuery
|
---|
29 | except:
|
---|
30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
31 | course_id = request.get('course_id')
|
---|
32 | mtool = context.portal_membership
|
---|
33 | member = mtool.getAuthenticatedMember()
|
---|
34 |
|
---|
35 |
|
---|
36 | d = context.getCourseInfo(course_id)
|
---|
37 | args = {}
|
---|
38 | err = ''
|
---|
39 | d['core_or_elective'] = True
|
---|
40 | while True:
|
---|
41 | if not course_id:
|
---|
42 | err = "Empty course id!"
|
---|
43 | break
|
---|
44 | if d['title'] == 'unknown':
|
---|
45 | err = "No such course!"
|
---|
46 | #logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id))
|
---|
47 | break
|
---|
48 | if context.hasObject(course_id):
|
---|
49 | err = "Course already exists!"
|
---|
50 | #logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id))
|
---|
51 | break
|
---|
52 | if context.hasObject("%s_co" % course_id):
|
---|
53 | err = "Course already exists as carryover course!"
|
---|
54 | #logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id))
|
---|
55 | break
|
---|
56 | break
|
---|
57 |
|
---|
58 | if err:
|
---|
59 | args['course_id'] = course_id
|
---|
60 | #args['error'] = err
|
---|
61 | args['portal_status_message'] = err
|
---|
62 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
63 | return request.RESPONSE.redirect(url)
|
---|
64 |
|
---|
65 |
|
---|
66 | # cr_id = context.invokeFactory('StudentCourseResult',course_id)
|
---|
67 | # cr = getattr(context,cr_id)
|
---|
68 | # context.portal_workflow.doActionFor(cr,'open')
|
---|
69 | # cr.getContent().edit(mapping=d)
|
---|
70 | d['course_id'] = course_id
|
---|
71 | d['student_id'] = student_id = context.getStudentId()
|
---|
72 | d['level_id'] = level_id = context.getId()
|
---|
73 | session_id = context.getLevelSession(context.getContent(),student_id,level_id)
|
---|
74 | d['session_id'] = session_id
|
---|
75 | d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
|
---|
76 |
|
---|
77 | context.course_results.addRecord(**d)
|
---|
78 | #context.portal_workflow.doActionFor(cr,'close')
|
---|
79 | #args['course_id'] = course_id
|
---|
80 |
|
---|
81 | logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member,
|
---|
82 | course_id,
|
---|
83 | level_id,
|
---|
84 | student_id))
|
---|
85 |
|
---|
86 | psm = "You successfully added course %s!" % course_id
|
---|
87 | args['portal_status_message'] = psm
|
---|
88 | if action_after_validate:
|
---|
89 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
90 | else:
|
---|
91 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
92 | return REQUEST.RESPONSE.redirect(url)
|
---|