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

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

some code cleaning

  • 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 5163 2010-04-21 04:38:00Z henrik $
9"""
10"""
11request = context.REQUEST
12import DateTime,logging
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18from Products.AdvancedQuery import Eq, Between, Le,In
19try:
20    aq_portal = context.portal_catalog.evalAdvancedQuery
21except:
22    aq_portal = context.portal_catalog_real.evalAdvancedQuery
23aq_courses = context.courses_catalog.evalAdvancedQuery
24
25import logging
26logger = logging.getLogger('Skins.refresh_level')
27
28from urllib import urlencode
29
30current = DateTime.DateTime()
31request = context.REQUEST
32#session = request.SESSION
33response = request.RESPONSE
34redirect = response.redirect
35logger = logging.getLogger('Skins.refresh_level')
36mtool = context.portal_membership
37member = mtool.getAuthenticatedMember()
38member_id = str(member)
39wt = context.waeup_tool
40student = context.students_catalog(id=context.getStudentId())[0]
41cert_id = student.course
42student_id = context.getStudentId()
43level = context
44level_id = context.getId()
45session_id = context.getLevelSession(level.getContent(),student_id,level_id)
46res = context.portal_catalog(portal_type="Certificate", id = cert_id)
47query = Eq('student_id',student_id) & Eq('level_id', level_id)
48existing_courses = [course.code for course in
49                    context.course_results.evalAdvancedQuery(query)]
50l = []
51records = []
52if res:
53    cert = res[0]
54    path = cert.getPath()
55    if int(student.level) > 0:
56        academics_level = 100 * (int(student.level)/100)
57    else:
58        academics_level = '000'
59    query = Eq("path","%s/%s" % (path,academics_level)) &\
60            Eq('portal_type','CertificateCourse')
61    courses = aq_portal(query)
62    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
63    for course_id in course_ids:
64        #set_trace()
65        if course_id in l:
66            # don't add twice
67            continue
68        l += course_id,
69        d = context.getCourseInfo(course_id)
70        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
71        d['course_id'] = course_id
72        d['student_id'] = student_id
73        d['level_id'] = level_id
74        d['session_id'] = session_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 level %s of %s' % (member,level_id,student_id))
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.