source: WAeUP_SRP/trunk/skins/waeup_student/refresh_level.py @ 1591

Last change on this file since 1591 was 1591, checked in by Henrik Bettermann, 18 years ago

fixed

  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[1590]1##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None
[1510]2# $Id: refresh_level.py 1591 2007-03-19 16:10:47Z henrik $
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
15aq_portal = context.portal_catalog.evalAdvancedQuery
16aq_courses = context.courses_catalog.evalAdvancedQuery
17
[1571]18import logging
19logger = logging.getLogger('Skins.refresh_level')
20
[1590]21from urllib import urlencode
22
[1510]23current = DateTime.DateTime()
24request = context.REQUEST
25session = request.SESSION
26response = request.RESPONSE
27redirect = response.redirect
[1571]28logger = logging.getLogger('Skins.refresh_level')
[1510]29mtool = context.portal_membership
30member = mtool.getAuthenticatedMember()
31member_id = str(member)
32wt = context.waeup_tool
33student = context.students_catalog(id=context.getStudentId())[0]
34cert_id = student.course
35current_level = student.level
36in_progress =  session.get('in_progress','finished')
37if in_progress == 'finished':
38    session.set('in_progress','started')
39    view = context.in_progress_view(refresh=3,page='study_level_view')
40    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
41    response.setHeader('Content-length','%d' % (len(view)))
42    response.setStatus('OK')
43    response.write(view)
44    response.write('')
45elif in_progress == 'started':
46    return
47level = context
48results = context.results_import(matric_no = student.matric_no)
49if results:
50    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
51    l = []
52    carry_overs = results
53    for co in carry_overs:
54        carry_over = False
55        query = Eq('code',co.CosCode)
56        c_res = aq_courses(query)
57        if not c_res:
[1571]58            logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode))
[1510]59            continue
60        course_cat_entry = c_res[0]
61        if not course_cat_entry.passmark:
62            carry_over = co.GRADE in ('D','E','F')
63        else:
64            try:
65                score = int(co.Score)
66            except:
[1571]67                logger.info('%s, course %s has invalid score %s' % (student.id,
[1510]68                                                                    co.CosCode,
69                                                                    co.Score))
70                continue
[1571]71            if int(c_res[0].passmark) <= score:
[1510]72                continue
73            carry_over = True
74        if not carry_over:
75            continue
76        d = context.getCourseInfo(co.CosCode)
77        d['grade'] = co.GRADE
78        d['carry_level'] = co.CarryLevel
79        course_id = "%s_co" % co.CosCode
80        if not context.hasObject(course_id):
81            cr_id = level.invokeFactory('StudentCourseResult',course_id)
82            course_result = getattr(level,cr_id)
83            context.portal_workflow.doActionFor(course_result,'open')
84            course_result.getContent().edit(mapping=d)
85res = context.portal_catalog(portal_type="Certificate", id = cert_id)
86l = []
87if res:
88    cert = res[0]
89    path = cert.getPath()
90    query = Eq("path",path) &\
91            Eq('portal_type','CertificateCourse') &\
92            Eq('SearchableText', "%s" % student.level)
93    courses = aq_portal(query)
94    for c in courses:
95        if not context.hasObject(c.getId):
96            d = context.getCourseInfo(c.getId)
97            cr_id = level.invokeFactory('StudentCourseResult',c.getId)
98            course_result = getattr(level,cr_id)
99            context.portal_workflow.doActionFor(course_result,'open')
100            d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
101            course_result.getContent().edit(mapping=d)
102session.set('in_progress','finished')
[1571]103logger.info('%s updated course list' % member)
[1590]104
[1591]105args = {}
[1590]106psm = "Course list updated!"
107args['portal_status_message'] = psm
108url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
109return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.