[1492] | 1 | ##parameters= |
---|
| 2 | # $Id: create_level.py 1552 2007-03-15 13:41:02Z joachim $ |
---|
| 3 | """ |
---|
| 4 | process the Application Form |
---|
| 5 | return html renderer + psm |
---|
| 6 | """ |
---|
| 7 | request = context.REQUEST |
---|
| 8 | import DateTime,logging |
---|
| 9 | try: |
---|
| 10 | from Products.zdb import set_trace |
---|
| 11 | except: |
---|
| 12 | def set_trace(): |
---|
| 13 | pass |
---|
[1494] | 14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 15 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
[1498] | 16 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
[1492] | 17 | |
---|
| 18 | current = DateTime.DateTime() |
---|
| 19 | request = context.REQUEST |
---|
| 20 | session = request.SESSION |
---|
| 21 | response = request.RESPONSE |
---|
| 22 | redirect = response.redirect |
---|
| 23 | logger = logging.getLogger('Student.create_level') |
---|
| 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | member_id = str(member) |
---|
| 27 | lt = context.portal_layouts |
---|
| 28 | wt = context.waeup_tool |
---|
| 29 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
| 30 | cert_id = student.course |
---|
[1494] | 31 | current_level = student.level |
---|
[1492] | 32 | in_progress = session.get('in_progress','finished') |
---|
| 33 | if in_progress == 'finished': |
---|
| 34 | session.set('in_progress','started') |
---|
[1494] | 35 | view = context.in_progress_view(refresh=3,page='%s/study_level_view' % current_level) |
---|
[1492] | 36 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 37 | response.setHeader('Content-length','%d' % (len(view))) |
---|
| 38 | response.setStatus('OK') |
---|
| 39 | response.write(view) |
---|
| 40 | response.write('') |
---|
| 41 | elif in_progress == 'started': |
---|
| 42 | return |
---|
[1552] | 43 | |
---|
| 44 | if context.hasObject(current_level): |
---|
| 45 | return |
---|
| 46 | level = getattr(context,current_level) |
---|
| 47 | return response.redirect("%s" % level.absolute_url()) |
---|
| 48 | |
---|
[1492] | 49 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
| 50 | level = getattr(context,"%s" % current_level) |
---|
[1495] | 51 | context.portal_workflow.doActionFor(level,'open') |
---|
[1494] | 52 | study_session = context.getSessionString() |
---|
| 53 | level.getContent().edit(mapping={'session': study_session}) |
---|
[1492] | 54 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
| 55 | results = context.results_import(matric_no = student.matric_no) |
---|
[1495] | 56 | if results: |
---|
[1498] | 57 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
[1495] | 58 | l = [] |
---|
[1498] | 59 | carry_overs = results |
---|
[1495] | 60 | for co in carry_overs: |
---|
[1498] | 61 | carry_over = False |
---|
| 62 | query = Eq('code',co.CosCode) |
---|
| 63 | c_res = aq_courses(query) |
---|
| 64 | if not c_res: |
---|
| 65 | logger.info('"%s","%s course not found in courses catalog"' % (student.id,co.CosCode)) |
---|
| 66 | continue |
---|
| 67 | course_cat_entry = c_res[0] |
---|
[1513] | 68 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
| 69 | if not passmark: |
---|
[1498] | 70 | carry_over = co.GRADE in ('D','E','F') |
---|
| 71 | else: |
---|
| 72 | try: |
---|
| 73 | score = int(co.Score) |
---|
| 74 | except: |
---|
| 75 | logger.info('"%s"," course %s invalid score %s"' % (student.id, |
---|
| 76 | co.CosCode, |
---|
| 77 | co.Score)) |
---|
| 78 | continue |
---|
| 79 | if int(c_res[0].passmark) <= score: |
---|
| 80 | continue |
---|
| 81 | carry_over = True |
---|
| 82 | if not carry_over: |
---|
| 83 | continue |
---|
[1495] | 84 | d = context.getCourseInfo(co.CosCode) |
---|
| 85 | d['grade'] = co.GRADE |
---|
| 86 | d['carry_level'] = co.CarryLevel |
---|
| 87 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
| 88 | course_result = getattr(level,cr_id) |
---|
| 89 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 90 | course_result.getContent().edit(mapping=d) |
---|
[1492] | 91 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 92 | l = [] |
---|
| 93 | if res: |
---|
| 94 | cert = res[0] |
---|
| 95 | path = cert.getPath() |
---|
| 96 | query = Eq("path",path) &\ |
---|
| 97 | Eq('portal_type','CertificateCourse') &\ |
---|
| 98 | Eq('SearchableText', "%s" % student.level) |
---|
[1494] | 99 | courses = aq_portal(query) |
---|
[1492] | 100 | for c in courses: |
---|
| 101 | d = context.getCourseInfo(c.getId) |
---|
[1494] | 102 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
[1495] | 103 | course_result = getattr(level,cr_id) |
---|
| 104 | context.portal_workflow.doActionFor(course_result,'open') |
---|
[1492] | 105 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
[1495] | 106 | course_result.getContent().edit(mapping=d) |
---|
[1492] | 107 | session.set('in_progress','finished') |
---|
[1498] | 108 | return |
---|