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