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= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: add_course_result.py 1520 2007-03-06 18:26:05Z joachim $ |
---|
11 | """ |
---|
12 | add a StudentCourseResult object |
---|
13 | """ |
---|
14 | from urllib import urlencode |
---|
15 | try: |
---|
16 | from Products.zdb import set_trace |
---|
17 | except: |
---|
18 | def set_trace(): |
---|
19 | pass |
---|
20 | request = context.REQUEST |
---|
21 | course_cat = context.courses_catalog |
---|
22 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
23 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
24 | course_id = request.get('course_id') |
---|
25 | d = context.getCourseInfo(course_id) |
---|
26 | args = {} |
---|
27 | err = '' |
---|
28 | while True: |
---|
29 | if d['title'] == 'unknown': |
---|
30 | err = "No such course" |
---|
31 | break |
---|
32 | if context.hasObject(course_id): |
---|
33 | err = "Course already exists" |
---|
34 | break |
---|
35 | if context.hasObject("%s_co" % course_id): |
---|
36 | err = "Course already exists as carryover course" |
---|
37 | break |
---|
38 | break |
---|
39 | |
---|
40 | if err: |
---|
41 | args['course_id'] = course_id |
---|
42 | args['error'] = err |
---|
43 | url = "%s?%s" % (context.absolute_url(),urlencode(args)) |
---|
44 | return request.RESPONSE.redirect(url) |
---|
45 | cr_id = context.invokeFactory('StudentCourseResult',course_id) |
---|
46 | #set_trace() |
---|
47 | cr = getattr(context,cr_id) |
---|
48 | context.portal_workflow.doActionFor(cr,'open') |
---|
49 | cr.getContent().edit(mapping=d) |
---|
50 | context.portal_workflow.doActionFor(cr,'close') |
---|
51 | args['course_id'] = course_id |
---|
52 | from urllib import urlencode |
---|
53 | url = "%s?%s" % (context.absolute_url(),urlencode(args)) |
---|
54 | return request.RESPONSE.redirect(url) |
---|
55 | |
---|