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

Last change on this file since 2613 was 2460, checked in by joachim, 17 years ago

fix refreshlevel + add_course_result

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