## 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 1571 2007-03-17 15:25:56Z henrik $ """ add a StudentCourseResult object """ import logging logger = logging.getLogger('Skins.add_course_result') 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') mtool = context.portal_membership member = mtool.getAuthenticatedMember() d = context.getCourseInfo(course_id) args = {} err = '' while True: if d['title'] == 'unknown': err = "No such course!" logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id)) break if context.hasObject(course_id): err = "Course already exists!" logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id)) break if context.hasObject("%s_co" % course_id): err = "Course already exists as carryover course!" logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id)) break break if err: args['course_id'] = course_id #args['error'] = err args['portal_status_message'] = 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 logger.info('%s added StudentCourseResult object %s' % (member,course_id)) from urllib import urlencode url = "%s?%s" % (context.absolute_url(),urlencode(args)) return request.RESPONSE.redirect(url)