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 2460 2007-10-28 14:46:29Z 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 | d = context.getCourseInfo(course_id)
|
---|
36 | args = {}
|
---|
37 | err = ''
|
---|
38 | d['core_or_elective'] = True
|
---|
39 | while True:
|
---|
40 | if not course_id:
|
---|
41 | err = "Empty course id!"
|
---|
42 | break
|
---|
43 | if d['title'] == 'unknown':
|
---|
44 | err = "No such course!"
|
---|
45 | break
|
---|
46 | d['course_id'] = course_id
|
---|
47 | d['student_id'] = student_id = context.getStudentId()
|
---|
48 | d['level_id'] = level_id = context.getId()
|
---|
49 | session_id = context.getLevelSession(context.getContent(),student_id,level_id)
|
---|
50 | d['session_id'] = session_id
|
---|
51 | d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
|
---|
52 | try:
|
---|
53 | context.course_results.addRecord(**d)
|
---|
54 | break
|
---|
55 | except ValueError:
|
---|
56 | err = "Course already exists!"
|
---|
57 | break
|
---|
58 | break
|
---|
59 |
|
---|
60 | if err:
|
---|
61 | args['course_id'] = course_id
|
---|
62 | args['portal_status_message'] = err
|
---|
63 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
64 | return request.RESPONSE.redirect(url)
|
---|
65 |
|
---|
66 |
|
---|
67 | logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member,
|
---|
68 | course_id,
|
---|
69 | level_id,
|
---|
70 | student_id))
|
---|
71 |
|
---|
72 | psm = "You successfully added course %s!" % course_id
|
---|
73 | args['portal_status_message'] = psm
|
---|
74 | if action_after_validate:
|
---|
75 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
76 | else:
|
---|
77 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
78 | return REQUEST.RESPONSE.redirect(url)
|
---|