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