source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/refresh_level.py @ 15344

Last change on this file since 15344 was 1597, checked in by joachim, 18 years ago

merged changes 1588:1596 from trunk to joachim-event-branch

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