##parameters= # $Id: create_level.py 1856 2007-06-05 13:06:23Z joachim $ """ process the Application Form return html renderer + psm """ request = context.REQUEST import DateTime,logging try: from Products.zdb import set_trace except: def set_trace(): pass from Products.AdvancedQuery import Eq, Between, Le,In try: aq_portal = context.portal_catalog.evalAdvancedQuery except: aq_portal = context.portal_catalog_real.evalAdvancedQuery aq_courses = context.courses_catalog.evalAdvancedQuery current = DateTime.DateTime() request = context.REQUEST #session = request.SESSION response = request.RESPONSE redirect = response.redirect logger = logging.getLogger('Skins.create_level') mtool = context.portal_membership member = mtool.getAuthenticatedMember() member_id = str(member) lt = context.portal_layouts wt = context.waeup_tool student = context.students_catalog(id=context.getStudentId())[0] cert_id = student.course current_level = student.level in_progress = request.get('in_progress','not started') level_created = request.get('level_created','xxx') create_level = request.get('create_level',None) ##if context.hasObject(current_level) and create_level: ## if getattr(context,current_level).objectIds(): ## logger.info('%s tried to add already existing level %s' % (student.id,current_level)) ## return logger.info('%s started to create level %s' % (student.id,current_level)) ##if in_progress in ('not started','started'): ## session.set('in_progress','started') ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started') ## response.setHeader('Content-type','text/html; charset=ISO-8859-15') ## response.setHeader('Content-length','%d' % (len(view))) ## response.setStatus('OK') ## response.write(view) ## response.write('') ## if in_progress == 'started': ## return if context.hasObject(current_level): level = getattr(context,"%s" % current_level) else: context.invokeFactory('StudentStudyLevel',"%s" % current_level) level = getattr(context,"%s" % current_level) context.portal_workflow.doActionFor(level,'open') study_session = context.getSessionString() level.getContent().edit(mapping={'session': study_session}) context.portal_workflow.doActionFor(level,'close_for_edit') context.waeup_tool.doCommit() results = [] if student.matric_no: results = context.results_import(matric_no = student.matric_no) if results: #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] l = [] carry_overs = results # carry_overs for probation students: yes or not, that is the question #if student.verdict == "C": # on probation # carry_overs = [] for co in carry_overs: cr_id = "%s_co" % co.CosCode if level.hasObject(cr_id): #already created continue carry_over = False query = Eq('code',co.CosCode) c_res = aq_courses(query) if not c_res: #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) continue course_cat_entry = c_res[0] passmark = getattr(course_cat_entry,'passmark',None) if not passmark: carry_over = co.GRADE in ('D','E','F') else: try: score = int(co.Score) except: # logger.info('%s, course %s has invalid score %s"' % (student.id, # co.CosCode, # co.Score)) continue if int(c_res[0].passmark) <= score: continue carry_over = True if not carry_over: continue d = context.getCourseInfo(co.CosCode) d['grade'] = co.GRADE d['carry_level'] = co.CarryLevel cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) course_result = getattr(level,cr_id) context.portal_workflow.doActionFor(course_result,'open') course_result.getContent().edit(mapping=d) context.waeup_tool.doCommit() #level['create_course_results'](cert_id,current_level) res = context.portal_catalog(portal_type="Certificate", id = cert_id) l = [] if res: cert = res[0] path = cert.getPath() #set_trace() query = Eq("path","%s/%s" % (path,current_level)) &\ Eq('portal_type','CertificateCourse') courses = aq_portal(query) for c in courses: cr_id = "%s" % c.getId if level.hasObject(cr_id): #already created continue d = context.getCourseInfo(c.getId) cr_id = level.invokeFactory('StudentCourseResult',c.getId) course_result = getattr(level,cr_id) context.portal_workflow.doActionFor(course_result,'open') d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') course_result.getContent().edit(mapping=d) context.waeup_tool.doCommit() logger.info('%s finished to create level %s' % (student.id,current_level)) return response.redirect("%s/%s" % (context.absolute_url(),current_level))