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

Last change on this file since 3058 was 2988, checked in by joachim, 17 years ago

this should work in all cases:

first the normal courses for a level are added, than the
carryover courses are added, which are not already in the level.

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