## Script (Python) "add_course_result" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: add_course_result.py 1520 2007-03-06 18:26:05Z joachim $ """ add a StudentCourseResult object """ from urllib import urlencode try: from Products.zdb import set_trace except: def set_trace(): pass request = context.REQUEST course_cat = context.courses_catalog from Products.AdvancedQuery import Eq, Between, Le,In aq_portal = context.portal_catalog.evalAdvancedQuery course_id = request.get('course_id') d = context.getCourseInfo(course_id) args = {} err = '' while True: if d['title'] == 'unknown': err = "No such course" break if context.hasObject(course_id): err = "Course already exists" break if context.hasObject("%s_co" % course_id): err = "Course already exists as carryover course" break break if err: args['course_id'] = course_id args['error'] = err url = "%s?%s" % (context.absolute_url(),urlencode(args)) return request.RESPONSE.redirect(url) cr_id = context.invokeFactory('StudentCourseResult',course_id) #set_trace() cr = getattr(context,cr_id) context.portal_workflow.doActionFor(cr,'open') cr.getContent().edit(mapping=d) context.portal_workflow.doActionFor(cr,'close') args['course_id'] = course_id from urllib import urlencode url = "%s?%s" % (context.absolute_url(),urlencode(args)) return request.RESPONSE.redirect(url)