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