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 |
---|
8 | # $Id: refresh_level.py 1592 2007-03-19 16:32:21Z henrik $ |
---|
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 | |
---|
24 | import logging |
---|
25 | logger = logging.getLogger('Skins.refresh_level') |
---|
26 | |
---|
27 | from urllib import urlencode |
---|
28 | |
---|
29 | current = DateTime.DateTime() |
---|
30 | request = context.REQUEST |
---|
31 | session = request.SESSION |
---|
32 | response = request.RESPONSE |
---|
33 | redirect = response.redirect |
---|
34 | logger = logging.getLogger('Skins.refresh_level') |
---|
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') |
---|
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 |
---|
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: |
---|
64 | logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
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: |
---|
73 | logger.info('%s, course %s has invalid score %s' % (student.id, |
---|
74 | co.CosCode, |
---|
75 | co.Score)) |
---|
76 | continue |
---|
77 | if int(c_res[0].passmark) <= score: |
---|
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') |
---|
109 | logger.info('%s updated course list' % member) |
---|
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) |
---|