1 | ##parameters=
|
---|
2 | # $Id: create_level.py 2794 2007-11-27 12:17:53Z 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 | aq_results = context.course_results.evalAdvancedQuery
|
---|
21 |
|
---|
22 | current = DateTime.DateTime()
|
---|
23 | request = context.REQUEST
|
---|
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 | requested_id = context.getStudentId()
|
---|
31 | #set_trace()
|
---|
32 | create_level = request.form.get('create_level',None)
|
---|
33 | if not create_level or not requested_id or\
|
---|
34 | (not context.isStaff() and member_id != requested_id):
|
---|
35 | logger.info('%s tried to access %s' % (member_id,requested_id))
|
---|
36 | return redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
37 | student_id = context.getStudentId()
|
---|
38 |
|
---|
39 | lt = context.portal_layouts
|
---|
40 | wt = context.waeup_tool
|
---|
41 | student = context.students_catalog.getRecordByKey(student_id)
|
---|
42 | cert_id = student.course
|
---|
43 | current_level = student.level
|
---|
44 | current_session = student.session
|
---|
45 | in_progress = request.get('in_progress','not started')
|
---|
46 | if aq_results(Eq('student_id',student_id) & Eq('level_id',current_level)):
|
---|
47 | logger.info('%s tried to create already existing level %s' % (student.id,current_level))
|
---|
48 | return
|
---|
49 |
|
---|
50 | logger.info('%s started to create level %s' % (student.id,current_level))
|
---|
51 |
|
---|
52 | if context.hasObject(current_level):
|
---|
53 | #level = getattr(context,"%s" % current_level)
|
---|
54 | return response.redirect("%s/%s" % (context.absolute_url(),current_level))
|
---|
55 | else:
|
---|
56 | context.invokeFactory('StudentStudyLevel',"%s" % current_level)
|
---|
57 | level = getattr(context,"%s" % current_level)
|
---|
58 | context.portal_workflow.doActionFor(level,'open')
|
---|
59 | level.getContent().edit(mapping={'session': current_session})
|
---|
60 | #context.portal_workflow.doActionFor(level,'close_for_edit')
|
---|
61 | level_id = level.getId()
|
---|
62 | session_id = context.getLevelSession(level.getContent(),student_id,level_id)
|
---|
63 | results = []
|
---|
64 | records = []
|
---|
65 | if student.matric_no:
|
---|
66 | results = context.results_import(matric_no = student.matric_no)
|
---|
67 | l = []
|
---|
68 |
|
---|
69 | # fetch carry_over courses from results_import
|
---|
70 | if student.session in ('6', '06') and results:
|
---|
71 | carry_overs = results
|
---|
72 | for co in carry_overs:
|
---|
73 | course_id = co.CosCode
|
---|
74 | if level.hasObject(course_id): #already created
|
---|
75 | continue
|
---|
76 | carry_over = False
|
---|
77 | query = Eq('code',co.CosCode)
|
---|
78 | c_res = aq_courses(query)
|
---|
79 | if not c_res:
|
---|
80 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,co.CosCode))
|
---|
81 | continue
|
---|
82 | course_cat_entry = c_res[0]
|
---|
83 | passmark = getattr(course_cat_entry,'passmark',None)
|
---|
84 | if not passmark or not co.Score:
|
---|
85 | carry_over = co.GRADE in ('D','E','F')
|
---|
86 | else:
|
---|
87 | try:
|
---|
88 | score = int(co.Score)
|
---|
89 | except:
|
---|
90 | # logger.info('%s, course %s has invalid score %s"' % (student.id,
|
---|
91 | # course_id,
|
---|
92 | # co.Score))
|
---|
93 | continue
|
---|
94 | if int(c_res[0].passmark) <= score:
|
---|
95 | continue
|
---|
96 | carry_over = True
|
---|
97 | if not carry_over:
|
---|
98 | continue
|
---|
99 | if course_id in l:
|
---|
100 | # don't add twice
|
---|
101 | continue
|
---|
102 | l += course_id,
|
---|
103 | d = context.getCourseInfo(co.CosCode)
|
---|
104 | d['course_id'] = course_id
|
---|
105 | d['carry_over'] = carry_over
|
---|
106 | d['code'] = course_id
|
---|
107 | d['student_id'] = student_id
|
---|
108 | d['level_id'] = level_id
|
---|
109 | d['session_id'] = session_id
|
---|
110 | records.append(d)
|
---|
111 | # fetch carry_over courses from the course_results catalog
|
---|
112 | else:
|
---|
113 | res = aq_results(Eq('student_id',student_id),
|
---|
114 | sortSpecs=('level_id',))
|
---|
115 | if res:
|
---|
116 | last_level_id = res[-1].level_id
|
---|
117 | for result in res:
|
---|
118 | course_id = result.code
|
---|
119 | if course_id in l or result.level_id != last_level_id:
|
---|
120 | continue
|
---|
121 | query = Eq('code',course_id)
|
---|
122 | c_res = aq_courses(query)
|
---|
123 | if not c_res:
|
---|
124 | #logger.info('%s", course %s not found in courses_catalog' % (student.id,result.CosCode))
|
---|
125 | continue
|
---|
126 | course_cat_entry = c_res[0]
|
---|
127 | passmark = getattr(course_cat_entry,'passmark',None)
|
---|
128 | try:
|
---|
129 | score = int(result.score)
|
---|
130 | except:
|
---|
131 | # logger.info('%s, course %s has invalid score %s"' % (student.id,
|
---|
132 | # course_id,
|
---|
133 | # result.Score))
|
---|
134 | continue
|
---|
135 | if int(c_res[0].passmark) <= score:
|
---|
136 | continue
|
---|
137 | l += course_id,
|
---|
138 | d = context.getCourseInfo(course_id)
|
---|
139 | d['course_id'] = course_id
|
---|
140 | d['carry_over'] = True
|
---|
141 | d['code'] = course_id
|
---|
142 | d['student_id'] = student_id
|
---|
143 | d['level_id'] = level_id
|
---|
144 | d['session_id'] = session_id
|
---|
145 | records.append(d)
|
---|
146 |
|
---|
147 | # fetch session courses from the certificate
|
---|
148 | res = context.portal_catalog(portal_type="Certificate", id = cert_id)
|
---|
149 | if res:
|
---|
150 | cert = res[0]
|
---|
151 | path = cert.getPath()
|
---|
152 | academics_level = 100 * (int(current_level)/100)
|
---|
153 | query = Eq("path","%s/%s" % (path,academics_level)) &\
|
---|
154 | Eq('portal_type','CertificateCourse')
|
---|
155 | courses = aq_portal(query)
|
---|
156 | for c in courses:
|
---|
157 | course_id = "%s" % c.getId
|
---|
158 | if course_id in l:
|
---|
159 | # don't add twice
|
---|
160 | continue
|
---|
161 | l += course_id,
|
---|
162 | d = context.getCourseInfo(c.getId)
|
---|
163 | d['carry_over'] = False
|
---|
164 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
|
---|
165 | d['course_id'] = course_id
|
---|
166 | d['student_id'] = student_id = context.getStudentId()
|
---|
167 | d['level_id'] = level_id
|
---|
168 | d['session_id'] = session_id
|
---|
169 | records.append(d)
|
---|
170 | if records:
|
---|
171 | context.course_results.addMultipleRecords(records)
|
---|
172 | logger.info('%s finished to create level %s' % (student.id,current_level))
|
---|
173 |
|
---|
174 | return response.redirect("%s/%s" % (context.absolute_url(),current_level)) |
---|