source: WAeUP_SRP/base/skins/waeup_student/refresh_level.py @ 2758

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

allow registration of probation levels

and more fixes

  • Property svn:keywords set to Id
File size: 2.8 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 2758 2007-11-25 22:06:28Z 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    academics_level = 100 * (int(student.level)/100)
57    query = Eq("path","%s/%s" % (path,academics_level)) &\
58            Eq('portal_type','CertificateCourse')
59    courses = aq_portal(query)
60    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
61    for course_id in course_ids:
62        #set_trace()
63        if course_id in l:
64            # don't add twice
65            continue
66        l += course_id,
67        d = context.getCourseInfo(course_id)
68        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
69        d['course_id'] = course_id
70        d['student_id'] = student_id
71        d['level_id'] = level_id
72        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
73        records.append(d)
74if records:
75    context.course_results.addMultipleRecords(records)
76
77#session.set('in_progress','finished')
78logger.info('%s updated course list' % member)
79
80args = {}
81psm = "Course list updated!"
82args['portal_status_message'] = psm
83if action_after_validate:
84    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
85else:
86    url = context.absolute_url() + '?' + urlencode(args)
87return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.