1 | ##parameters= |
---|
2 | # $Id: create_level.py 1576 2007-03-18 14:48:06Z 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('Skins.create_level') |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | member_id = str(member) |
---|
27 | lt = context.portal_layouts |
---|
28 | wt = context.waeup_tool |
---|
29 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
30 | cert_id = student.course |
---|
31 | current_level = student.level |
---|
32 | in_progress = request.get('in_progress','not started') |
---|
33 | |
---|
34 | if context.hasObject(current_level): |
---|
35 | response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
36 | return |
---|
37 | |
---|
38 | if in_progress in ('not started','started'): |
---|
39 | session.set('in_progress','started') |
---|
40 | view = context.in_progress_view(refresh=3,page='create_level?in_progress=started') |
---|
41 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
42 | response.setHeader('Content-length','%d' % (len(view))) |
---|
43 | response.setStatus('OK') |
---|
44 | response.write(view) |
---|
45 | response.write('') |
---|
46 | if in_progress == 'started': |
---|
47 | return |
---|
48 | |
---|
49 | |
---|
50 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
51 | level = getattr(context,"%s" % current_level) |
---|
52 | context.portal_workflow.doActionFor(level,'open') |
---|
53 | study_session = context.getSessionString() |
---|
54 | level.getContent().edit(mapping={'session': study_session}) |
---|
55 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
56 | results = context.results_import(matric_no = student.matric_no) |
---|
57 | if results: |
---|
58 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
59 | l = [] |
---|
60 | carry_overs = results |
---|
61 | for co in carry_overs: |
---|
62 | carry_over = False |
---|
63 | query = Eq('code',co.CosCode) |
---|
64 | c_res = aq_courses(query) |
---|
65 | if not c_res: |
---|
66 | logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
67 | continue |
---|
68 | course_cat_entry = c_res[0] |
---|
69 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
70 | if not passmark: |
---|
71 | carry_over = co.GRADE in ('D','E','F') |
---|
72 | else: |
---|
73 | try: |
---|
74 | score = int(co.Score) |
---|
75 | except: |
---|
76 | logger.info('%s, course %s has invalid score %s"' % (student.id, |
---|
77 | co.CosCode, |
---|
78 | co.Score)) |
---|
79 | continue |
---|
80 | if int(c_res[0].passmark) <= score: |
---|
81 | continue |
---|
82 | carry_over = True |
---|
83 | if not carry_over: |
---|
84 | continue |
---|
85 | d = context.getCourseInfo(co.CosCode) |
---|
86 | d['grade'] = co.GRADE |
---|
87 | d['carry_level'] = co.CarryLevel |
---|
88 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
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() |
---|
97 | query = Eq("path",path) &\ |
---|
98 | Eq('portal_type','CertificateCourse') &\ |
---|
99 | Eq('SearchableText', "%s" % student.level) |
---|
100 | courses = aq_portal(query) |
---|
101 | for c in courses: |
---|
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 | return |
---|