1 | ##parameters= |
---|
2 | # $Id: create_level.py 1845 2007-06-02 11:01:49Z 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 | try: |
---|
16 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
17 | except: |
---|
18 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
19 | aq_courses = context.courses_catalog.evalAdvancedQuery |
---|
20 | |
---|
21 | current = DateTime.DateTime() |
---|
22 | request = context.REQUEST |
---|
23 | #session = request.SESSION |
---|
24 | response = request.RESPONSE |
---|
25 | redirect = response.redirect |
---|
26 | logger = logging.getLogger('Skins.create_level') |
---|
27 | mtool = context.portal_membership |
---|
28 | member = mtool.getAuthenticatedMember() |
---|
29 | member_id = str(member) |
---|
30 | lt = context.portal_layouts |
---|
31 | wt = context.waeup_tool |
---|
32 | student = context.students_catalog(id=context.getStudentId())[0] |
---|
33 | cert_id = student.course |
---|
34 | current_level = student.level |
---|
35 | in_progress = request.get('in_progress','not started') |
---|
36 | level_created = request.get('level_created','xxx') |
---|
37 | create_level = request.get('create_level',None) |
---|
38 | |
---|
39 | if context.hasObject(current_level) and create_level : |
---|
40 | logger.info('%s tried to add already existing level %s' % (student.id,current_level)) |
---|
41 | return |
---|
42 | logger.info('%s started to create level %s' % (student.id,current_level)) |
---|
43 | |
---|
44 | ##if in_progress in ('not started','started'): |
---|
45 | ## session.set('in_progress','started') |
---|
46 | ## view = context.in_progress_view(refresh=20,page='create_level?in_progress=started') |
---|
47 | ## response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
48 | ## response.setHeader('Content-length','%d' % (len(view))) |
---|
49 | ## response.setStatus('OK') |
---|
50 | ## response.write(view) |
---|
51 | ## response.write('') |
---|
52 | ## if in_progress == 'started': |
---|
53 | ## return |
---|
54 | |
---|
55 | if level_created == current_level: |
---|
56 | level = getattr(context,"%s" % current_level) |
---|
57 | else: |
---|
58 | context.invokeFactory('StudentStudyLevel',"%s" % current_level) |
---|
59 | level = getattr(context,"%s" % current_level) |
---|
60 | context.portal_workflow.doActionFor(level,'open') |
---|
61 | study_session = context.getSessionString() |
---|
62 | level.getContent().edit(mapping={'session': study_session}) |
---|
63 | context.portal_workflow.doActionFor(level,'close_for_edit') |
---|
64 | results = [] |
---|
65 | if student.matric_no: |
---|
66 | results = context.results_import(matric_no = student.matric_no) |
---|
67 | if results: |
---|
68 | #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')] |
---|
69 | l = [] |
---|
70 | carry_overs = results |
---|
71 | |
---|
72 | # carry_overs for probation students: yes or not, that is the question |
---|
73 | #if student.verdict == "C": # on probation |
---|
74 | # carry_overs = [] |
---|
75 | |
---|
76 | for co in carry_overs: |
---|
77 | carry_over = False |
---|
78 | query = Eq('code',co.CosCode) |
---|
79 | c_res = aq_courses(query) |
---|
80 | if not c_res: |
---|
81 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode)) |
---|
82 | continue |
---|
83 | course_cat_entry = c_res[0] |
---|
84 | passmark = getattr(course_cat_entry,'passmark',None) |
---|
85 | if not passmark: |
---|
86 | carry_over = co.GRADE in ('D','E','F') |
---|
87 | else: |
---|
88 | try: |
---|
89 | score = int(co.Score) |
---|
90 | except: |
---|
91 | # logger.info('%s, course %s has invalid score %s"' % (student.id, |
---|
92 | # co.CosCode, |
---|
93 | # co.Score)) |
---|
94 | continue |
---|
95 | if int(c_res[0].passmark) <= score: |
---|
96 | continue |
---|
97 | carry_over = True |
---|
98 | if not carry_over: |
---|
99 | continue |
---|
100 | d = context.getCourseInfo(co.CosCode) |
---|
101 | d['grade'] = co.GRADE |
---|
102 | d['carry_level'] = co.CarryLevel |
---|
103 | cr_id = level.invokeFactory('StudentCourseResult',"%s_co" % co.CosCode) |
---|
104 | course_result = getattr(level,cr_id) |
---|
105 | context.portal_workflow.doActionFor(course_result,'open') |
---|
106 | course_result.getContent().edit(mapping=d) |
---|
107 | #context.waeup_tool.doCommit() |
---|
108 | #level['create_course_results'](cert_id,current_level) |
---|
109 | res = context.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
110 | l = [] |
---|
111 | if res: |
---|
112 | cert = res[0] |
---|
113 | path = cert.getPath() |
---|
114 | #set_trace() |
---|
115 | query = Eq("path","%s/%s" % (path,current_level)) &\ |
---|
116 | Eq('portal_type','CertificateCourse') |
---|
117 | courses = aq_portal(query) |
---|
118 | for c in courses: |
---|
119 | d = context.getCourseInfo(c.getId) |
---|
120 | cr_id = level.invokeFactory('StudentCourseResult',c.getId) |
---|
121 | course_result = getattr(level,cr_id) |
---|
122 | context.portal_workflow.doActionFor(course_result,'open') |
---|
123 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
124 | course_result.getContent().edit(mapping=d) |
---|
125 | #context.waeup_tool.doCommit() |
---|
126 | logger.info('%s finished to create level %s' % (student.id,current_level)) |
---|
127 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|
128 | |
---|