## 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 2451 2007-10-27 14:26:41Z 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 = '' d['core_or_elective'] = True 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) # cr = getattr(context,cr_id) # context.portal_workflow.doActionFor(cr,'open') # cr.getContent().edit(mapping=d) d['course_id'] = course_id d['student_id'] = student_id = context.getStudentId() d['level_id'] = level_id = context.getId() session_id = context.getLevelSession(context.getContent(),student_id,level_id) d['session_id'] = session_id d['key'] = "%s|%s|%s" % (student_id,level_id,course_id) context.course_results.addRecord(**d) #context.portal_workflow.doActionFor(cr,'close') #args['course_id'] = course_id logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member, course_id, level_id, student_id)) 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)