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

Last change on this file since 5160 was 5144, checked in by Henrik Bettermann, 15 years ago

fix schools #17

  • Property svn:keywords set to Id
File size: 3.0 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 5144 2010-04-13 07:27:13Z 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()
47session_id = context.getLevelSession(level.getContent(),student_id,level_id)
48res = context.portal_catalog(portal_type="Certificate", id = cert_id)
49query = Eq('student_id',student_id) & Eq('level_id', level_id)
50existing_courses = [course.code for course in
51                    context.course_results.evalAdvancedQuery(query)]
52l = []
53records = []
54if res:
55    cert = res[0]
56    path = cert.getPath()
57    if int(student.level) > 0:
58        academics_level = 100 * (int(student.level)/100)
59    else:
60        academics_level = '000'
61    query = Eq("path","%s/%s" % (path,academics_level)) &\
62            Eq('portal_type','CertificateCourse')
63    courses = aq_portal(query)
64    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
65    for course_id in course_ids:
66        #set_trace()
67        if course_id in l:
68            # don't add twice
69            continue
70        l += course_id,
71        d = context.getCourseInfo(course_id)
72        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
73        d['course_id'] = course_id
74        d['student_id'] = student_id
75        d['level_id'] = level_id
76        d['session_id'] = session_id
77        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
78        records.append(d)
79if records:
80    context.course_results.addMultipleRecords(records)
81
82#session.set('in_progress','finished')
83logger.info('%s updated level %s of %s' % (member,level_id,student_id))
84
85args = {}
86psm = "Course list updated!"
87args['portal_status_message'] = psm
88if action_after_validate:
89    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
90else:
91    url = context.absolute_url() + '?' + urlencode(args)
92return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.