## Script (Python) "add_course_result" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST=None, action_after_validate='' ##title= ## # $Id: add_course_result.py 1863 2007-06-08 07:16:23Z joachim $ """ 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 try: aq_portal = context.portal_catalog.evalAdvancedQuery except: aq_portal = context.portal_catalog_real.evalAdvancedQuery course_id = request.get('course_id') mtool = context.portal_membership member = mtool.getAuthenticatedMember() d = context.getCourseInfo(course_id) args = {} err = '' while True: if not course_id: err = "Empty course id!" break 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 = context.absolute_url() + '/' + action_after_validate + '?' + 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 for %s' % (member,course_id,context.getStudentId())) psm = "You successfully added course %s!" % course_id args['portal_status_message'] = psm if action_after_validate: url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) else: url = context.absolute_url() + '?' + urlencode(args) return REQUEST.RESPONSE.redirect(url)