[1592] | 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 |
---|
[1590] | 7 | ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None |
---|
[1510] | 8 | # $Id: refresh_level.py 1657 2007-03-28 09:43:17Z 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 | |
---|
[1571] | 24 | import logging |
---|
| 25 | logger = logging.getLogger('Skins.refresh_level') |
---|
| 26 | |
---|
[1590] | 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 |
---|
[1571] | 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 |
---|
[1657] | 42 | ##in_progress = session.get('in_progress','finished') |
---|
| 43 | ##if in_progress == 'finished': |
---|
| 44 | ## session.set('in_progress','started') |
---|
| 45 | ## view = context.in_progress_view(refresh=3,page=action_after_validate) |
---|
| 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 |
---|
[1510] | 53 | level = context |
---|
[1657] | 54 | #results = context.results_import(matric_no = student.matric_no) |
---|
| 55 | results = False #skip carry overs |
---|
[1510] | 56 | if results: |
---|
| 57 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
| 58 | l = [] |
---|
| 59 | carry_overs = results |
---|
| 60 | for co in carry_overs: |
---|
| 61 | carry_over = False |
---|
| 62 | query = Eq('code',co.CosCode) |
---|
| 63 | c_res = aq_courses(query) |
---|
| 64 | if not c_res: |
---|
[1571] | 65 | logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
[1510] | 66 | continue |
---|
| 67 | course_cat_entry = c_res[0] |
---|
| 68 | if not course_cat_entry.passmark: |
---|
| 69 | carry_over = co.GRADE in ('D','E','F') |
---|
| 70 | else: |
---|
| 71 | try: |
---|
| 72 | score = int(co.Score) |
---|
| 73 | except: |
---|
[1571] | 74 | logger.info('%s, course %s has invalid score %s' % (student.id, |
---|
[1510] | 75 | co.CosCode, |
---|
| 76 | co.Score)) |
---|
| 77 | continue |
---|
[1571] | 78 | if int(c_res[0].passmark) <= score: |
---|
[1510] | 79 | continue |
---|
| 80 | carry_over = True |
---|
| 81 | if not carry_over: |
---|
| 82 | continue |
---|
| 83 | d = context.getCourseInfo(co.CosCode) |
---|
| 84 | d['grade'] = co.GRADE |
---|
| 85 | d['carry_level'] = co.CarryLevel |
---|
| 86 | course_id = "%s_co" % co.CosCode |
---|
| 87 | if not context.hasObject(course_id): |
---|
| 88 | cr_id = level.invokeFactory('StudentCourseResult',course_id) |
---|
| 89 | course_result = getattr(level,cr_id) |
---|
| 90 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 91 | course_result.getContent().edit(mapping=d) |
---|
| 92 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 93 | l = [] |
---|
| 94 | if res: |
---|
| 95 | cert = res[0] |
---|
| 96 | path = cert.getPath() |
---|
[1657] | 97 | query = Eq("path","%s/%s" % (path,student.level)) &\ |
---|
| 98 | Eq('portal_type','CertificateCourse') |
---|
[1510] | 99 | courses = aq_portal(query) |
---|
| 100 | for c in courses: |
---|
[1657] | 101 | #set_trace() |
---|
[1510] | 102 | if not context.hasObject(c.getId): |
---|
| 103 | d = context.getCourseInfo(c.getId) |
---|
| 104 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
| 105 | course_result = getattr(level,cr_id) |
---|
| 106 | context.portal_workflow.doActionFor(course_result,'open') |
---|
| 107 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 108 | course_result.getContent().edit(mapping=d) |
---|
| 109 | session.set('in_progress','finished') |
---|
[1571] | 110 | logger.info('%s updated course list' % member) |
---|
[1590] | 111 | |
---|
[1591] | 112 | args = {} |
---|
[1590] | 113 | psm = "Course list updated!" |
---|
| 114 | args['portal_status_message'] = psm |
---|
[1606] | 115 | if action_after_validate: |
---|
| 116 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
| 117 | else: |
---|
| 118 | url = context.absolute_url() + '?' + urlencode(args) |
---|
[1590] | 119 | return REQUEST.RESPONSE.redirect(url) |
---|