[1597] | 1 | ## Script (Python) "refresh_level" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None |
---|
[1510] | 8 | # $Id: refresh_level.py 1597 2007-03-19 21:59:41Z joachim $ |
---|
| 9 | """ |
---|
| 10 | process the Application Form |
---|
| 11 | return html renderer + psm |
---|
| 12 | """ |
---|
| 13 | request = context.REQUEST |
---|
| 14 | import DateTime,logging |
---|
| 15 | try: |
---|
| 16 | from Products.zdb import set_trace |
---|
| 17 | except: |
---|
| 18 | def set_trace(): |
---|
| 19 | pass |
---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 21 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 22 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
| 23 | |
---|
[1596] | 24 | import logging |
---|
| 25 | logger = logging.getLogger('Skins.refresh_level') |
---|
| 26 | |
---|
[1597] | 27 | from urllib import urlencode |
---|
| 28 | |
---|
[1510] | 29 | current = DateTime.DateTime() |
---|
| 30 | request = context.REQUEST |
---|
| 31 | session = request.SESSION |
---|
| 32 | response = request.RESPONSE |
---|
| 33 | redirect = response.redirect |
---|
[1596] | 34 | logger = logging.getLogger('Skins.refresh_level') |
---|
[1510] | 35 | mtool = context.portal_membership |
---|
| 36 | member = mtool.getAuthenticatedMember() |
---|
| 37 | member_id = str(member) |
---|
| 38 | wt = context.waeup_tool |
---|
| 39 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
| 40 | cert_id = student.course |
---|
| 41 | current_level = student.level |
---|
| 42 | in_progress = session.get('in_progress','finished') |
---|
| 43 | if in_progress == 'finished': |
---|
| 44 | session.set('in_progress','started') |
---|
[1597] | 45 | view = context.in_progress_view(refresh=3,page=action_after_validate) |
---|
[1510] | 46 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 47 | response.setHeader('Content-length','%d' % (len(view))) |
---|
| 48 | response.setStatus('OK') |
---|
| 49 | response.write(view) |
---|
| 50 | response.write('') |
---|
| 51 | elif in_progress == 'started': |
---|
| 52 | return |
---|
| 53 | level = context |
---|
| 54 | results = context.results_import(matric_no = student.matric_no) |
---|
| 55 | if results: |
---|
| 56 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
| 57 | l = [] |
---|
| 58 | carry_overs = results |
---|
| 59 | for co in carry_overs: |
---|
| 60 | carry_over = False |
---|
| 61 | query = Eq('code',co.CosCode) |
---|
| 62 | c_res = aq_courses(query) |
---|
| 63 | if not c_res: |
---|
[1596] | 64 | logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
[1510] | 65 | continue |
---|
| 66 | course_cat_entry = c_res[0] |
---|
| 67 | if not course_cat_entry.passmark: |
---|
| 68 | carry_over = co.GRADE in ('D','E','F') |
---|
| 69 | else: |
---|
| 70 | try: |
---|
| 71 | score = int(co.Score) |
---|
| 72 | except: |
---|
[1596] | 73 | logger.info('%s, course %s has invalid score %s' % (student.id, |
---|
[1510] | 74 | co.CosCode, |
---|
| 75 | co.Score)) |
---|
| 76 | continue |
---|
[1596] | 77 | if int(c_res[0].passmark) <= score: |
---|
[1510] | 78 | continue |
---|
| 79 | carry_over = True |
---|
| 80 | if not carry_over: |
---|
| 81 | continue |
---|
| 82 | d = context.getCourseInfo(co.CosCode) |
---|
| 83 | d['grade'] = co.GRADE |
---|
| 84 | d['carry_level'] = co.CarryLevel |
---|
| 85 | course_id = "%s_co" % co.CosCode |
---|
| 86 | if not context.hasObject(course_id): |
---|
| 87 | cr_id = level.invokeFactory('StudentCourseResult',course_id) |
---|
| 88 | course_result = getattr(level,cr_id) |
---|
| 89 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 90 | course_result.getContent().edit(mapping=d) |
---|
| 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) |
---|
| 99 | courses = aq_portal(query) |
---|
| 100 | for c in courses: |
---|
| 101 | if not context.hasObject(c.getId): |
---|
| 102 | d = context.getCourseInfo(c.getId) |
---|
| 103 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
| 104 | course_result = getattr(level,cr_id) |
---|
| 105 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 106 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 107 | course_result.getContent().edit(mapping=d) |
---|
| 108 | session.set('in_progress','finished') |
---|
[1596] | 109 | logger.info('%s updated course list' % member) |
---|
[1597] | 110 | |
---|
| 111 | args = {} |
---|
| 112 | psm = "Course list updated!" |
---|
| 113 | args['portal_status_message'] = psm |
---|
| 114 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
| 115 | return REQUEST.RESPONSE.redirect(url) |
---|