[1519] | 1 | ## Script (Python) "add_course_result" |
---|
[731] | 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 | ## |
---|
[805] | 10 | # $Id: add_course_result.py 1520 2007-03-06 18:26:05Z joachim $ |
---|
[731] | 11 | """ |
---|
[1519] | 12 | add a StudentCourseResult object |
---|
[731] | 13 | """ |
---|
[1482] | 14 | from urllib import urlencode |
---|
[1520] | 15 | try: |
---|
| 16 | from Products.zdb import set_trace |
---|
| 17 | except: |
---|
| 18 | def set_trace(): |
---|
| 19 | pass |
---|
[1482] | 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': |
---|
[1519] | 30 | err = "No such course" |
---|
[1482] | 31 | break |
---|
| 32 | if context.hasObject(course_id): |
---|
[1519] | 33 | err = "Course already exists" |
---|
[1482] | 34 | break |
---|
| 35 | if context.hasObject("%s_co" % course_id): |
---|
[1519] | 36 | err = "Course already exists as carryover course" |
---|
[1482] | 37 | break |
---|
| 38 | break |
---|
[731] | 39 | |
---|
[1482] | 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) |
---|
[1520] | 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') |
---|
[1482] | 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 | |
---|