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

Last change on this file since 4550 was 3074, checked in by Henrik Bettermann, 17 years ago

calculate correct level in academics section

  • Property svn:keywords set to Id
File size: 2.9 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 3074 2008-01-31 16:41:48Z henrik $
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
21try:
22    aq_portal = context.portal_catalog.evalAdvancedQuery
23except:
24    aq_portal = context.portal_catalog_real.evalAdvancedQuery
25aq_courses = context.courses_catalog.evalAdvancedQuery
26
27import logging
28logger = logging.getLogger('Skins.refresh_level')
29
30from urllib import urlencode
31
32current = DateTime.DateTime()
33request = context.REQUEST
34#session = request.SESSION
35response = request.RESPONSE
36redirect = response.redirect
37logger = logging.getLogger('Skins.refresh_level')
38mtool = context.portal_membership
39member = mtool.getAuthenticatedMember()
40member_id = str(member)
41wt = context.waeup_tool
42student = context.students_catalog(id=context.getStudentId())[0]
43cert_id = student.course
44student_id = context.getStudentId()
45level = context
46level_id = context.getId()
47res = context.portal_catalog(portal_type="Certificate", id = cert_id)
48query = Eq('student_id',student_id) & Eq('level_id', level_id)
49existing_courses = [course.code for course in
50                    context.course_results.evalAdvancedQuery(query)]
51l = []
52records = []
53if res:
54    cert = res[0]
55    path = cert.getPath()
56    if int(student.level) > 0:
57        academics_level = 100 * (int(student.level)/100)
58    else:
59        academics_level = '000'
60    query = Eq("path","%s/%s" % (path,academics_level)) &\
61            Eq('portal_type','CertificateCourse')
62    courses = aq_portal(query)
63    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
64    for course_id in course_ids:
65        #set_trace()
66        if course_id in l:
67            # don't add twice
68            continue
69        l += course_id,
70        d = context.getCourseInfo(course_id)
71        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
72        d['course_id'] = course_id
73        d['student_id'] = student_id
74        d['level_id'] = level_id
75        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
76        records.append(d)
77if records:
78    context.course_results.addMultipleRecords(records)
79
80#session.set('in_progress','finished')
81logger.info('%s updated course list' % member)
82
83args = {}
84psm = "Course list updated!"
85args['portal_status_message'] = psm
86if action_after_validate:
87    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
88else:
89    url = context.absolute_url() + '?' + urlencode(args)
90return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.