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