source: WAeUP_SRP/base/skins/waeup_student/create_level.py @ 2784

Last change on this file since 2784 was 2766, checked in by joachim, 17 years ago

M skins/waeup_student/create_level.py
use course_results for carry_overs

M skins/waeup_pins/pins_view.pt
M skins/waeup_pins/search_pins.py
sort batches in select-box

M Widgets.py
M WAeUPTables.py
M WAeUPTool.py
mass_(create,edit)_courseresults edits verdict in level.

M profiles/default/layouts/application_cest.xml
M profiles/default/applicants_catalog.xml
new meta_data field "serial", index must be added manually

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1##parameters=
2# $Id: create_level.py 2766 2007-11-26 19:18:09Z joachim $
3"""
4process the Application Form
5return html renderer + psm
6"""
7request = context.REQUEST
8import DateTime,logging
9try:
10    from Products.zdb import set_trace
11except:
12    def set_trace():
13        pass
14from Products.AdvancedQuery import Eq, Between, Le,In
15try:
16    aq_portal = context.portal_catalog.evalAdvancedQuery
17except:
18    aq_portal = context.portal_catalog_real.evalAdvancedQuery
19aq_courses = context.courses_catalog.evalAdvancedQuery
20aq_results = context.course_results.evalAdvancedQuery
21
22current = DateTime.DateTime()
23request = context.REQUEST
24response = request.RESPONSE
25redirect = response.redirect
26logger = logging.getLogger('Skins.create_level')
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29member_id = str(member)
30requested_id = context.getStudentId()
31#set_trace()
32create_level =  request.form.get('create_level',None)
33if 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())
37student_id = context.getStudentId()
38
39lt = context.portal_layouts
40wt = context.waeup_tool
41student = context.students_catalog.getRecordByKey(student_id)
42cert_id = student.course
43current_level = student.level
44current_session = student.session
45in_progress =  request.get('in_progress','not started')
46if 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
50logger.info('%s started to create level %s' % (student.id,current_level))
51
52if context.hasObject(current_level):
53    #level = getattr(context,"%s" % current_level)
54    return response.redirect("%s/%s" % (context.absolute_url(),current_level))
55else:
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')
61level_id = level.getId()
62session_id = context.getLevelSession(level.getContent(),student_id,level_id)
63results = []
64records = []
65if student.matric_no:
66    results = context.results_import(matric_no = student.matric_no)
67l = []
68
69# fetch carry_over courses from results_import
70if 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
112else:
113    res = context.aq_results(Eq('student_id',student_id),
114                             sortSpecs=('level_id',))
115    last_level_id = res[-1].level_id
116    for result in res:
117        course_id = result.code
118        if course_id in l or result.level_id != last_level_id:
119            continue
120        query = Eq('code',course_id)
121        c_res = aq_courses(query)
122        if not c_res:
123            #logger.info('%s", course %s not found in courses_catalog' % (student.id,result.CosCode))
124            continue
125        course_cat_entry = c_res[0]
126        passmark = getattr(course_cat_entry,'passmark',None)
127        try:
128            score = int(result.score)
129        except:
130            # logger.info('%s, course %s has invalid score %s"' % (student.id,
131            #                                                     course_id,
132            #                                                     result.Score))
133            continue
134        if int(c_res[0].passmark) <= score:
135            continue
136        l += course_id,
137        d = context.getCourseInfo(course_id)
138        d['course_id'] = course_id
139        d['carry_over'] = True
140        d['code'] = course_id
141        d['student_id'] = student_id
142        d['level_id'] = level_id
143        d['session_id'] = session_id
144        records.append(d)
145
146# fetch session courses from the certificate
147res = context.portal_catalog(portal_type="Certificate", id = cert_id)
148if res:
149    cert = res[0]
150    path = cert.getPath()
151    academics_level = 100 * (int(current_level)/100)
152    query = Eq("path","%s/%s" % (path,academics_level)) &\
153            Eq('portal_type','CertificateCourse')
154    courses = aq_portal(query)
155    for c in courses:
156        course_id = "%s" % c.getId
157        if course_id in l:
158            # don't add twice
159            continue
160        l += course_id,
161        d = context.getCourseInfo(c.getId)
162        d['carry_over'] = False
163        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
164        d['course_id'] = course_id
165        d['student_id'] = student_id = context.getStudentId()
166        d['level_id'] = level_id
167        d['session_id'] = session_id
168        records.append(d)
169if records:
170    context.course_results.addMultipleRecords(records)
171logger.info('%s finished to create level %s' % (student.id,current_level))
172
173return response.redirect("%s/%s" % (context.absolute_url(),current_level))
Note: See TracBrowser for help on using the repository browser.