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

Last change on this file since 1784 was 1657, checked in by joachim, 18 years ago

fix for #168

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
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
8# $Id: refresh_level.py 1657 2007-03-28 09:43:17Z 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
24import logging
25logger = logging.getLogger('Skins.refresh_level')
26
27from urllib import urlencode
28
29current = DateTime.DateTime()
30request = context.REQUEST
31session = request.SESSION
32response = request.RESPONSE
33redirect = response.redirect
34logger = logging.getLogger('Skins.refresh_level')
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
42##in_progress =  session.get('in_progress','finished')
43##if in_progress == 'finished':
44##    session.set('in_progress','started')
45##    view = context.in_progress_view(refresh=3,page=action_after_validate)
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('')
51##elif in_progress == 'started':
52##    return
53level = context
54#results = context.results_import(matric_no = student.matric_no)
55results = False #skip carry overs
56if results:
57    #carry_overs = [brain for brain in results if brain.GRADE in ('D','E','F')]
58    l = []
59    carry_overs = results
60    for co in carry_overs:
61        carry_over = False
62        query = Eq('code',co.CosCode)
63        c_res = aq_courses(query)
64        if not c_res:
65            logger.info('%s, course %s not found in courses_catalog' % (student.id,co.CosCode))
66            continue
67        course_cat_entry = c_res[0]
68        if not course_cat_entry.passmark:
69            carry_over = co.GRADE in ('D','E','F')
70        else:
71            try:
72                score = int(co.Score)
73            except:
74                logger.info('%s, course %s has invalid score %s' % (student.id,
75                                                                    co.CosCode,
76                                                                    co.Score))
77                continue
78            if int(c_res[0].passmark) <= score:
79                continue
80            carry_over = True
81        if not carry_over:
82            continue
83        d = context.getCourseInfo(co.CosCode)
84        d['grade'] = co.GRADE
85        d['carry_level'] = co.CarryLevel
86        course_id = "%s_co" % co.CosCode
87        if not context.hasObject(course_id):
88            cr_id = level.invokeFactory('StudentCourseResult',course_id)
89            course_result = getattr(level,cr_id)
90            context.portal_workflow.doActionFor(course_result,'open')
91            course_result.getContent().edit(mapping=d)
92res = context.portal_catalog(portal_type="Certificate", id = cert_id)
93l = []
94if res:
95    cert = res[0]
96    path = cert.getPath()
97    query = Eq("path","%s/%s" % (path,student.level)) &\
98            Eq('portal_type','CertificateCourse')
99    courses = aq_portal(query)
100    for c in courses:
101        #set_trace()
102        if not context.hasObject(c.getId):
103            d = context.getCourseInfo(c.getId)
104            cr_id = level.invokeFactory('StudentCourseResult',c.getId)
105            course_result = getattr(level,cr_id)
106            context.portal_workflow.doActionFor(course_result,'open')
107            d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
108            course_result.getContent().edit(mapping=d)
109session.set('in_progress','finished')
110logger.info('%s updated course list' % member)
111
112args = {}
113psm = "Course list updated!"
114args['portal_status_message'] = psm
115if action_after_validate:
116    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
117else:
118    url = context.absolute_url() + '?' + urlencode(args)
119return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.