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

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

some code cleaning

  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[2448]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
[2460]42student_id = context.getStudentId()
[2448]43level = context
[2460]44level_id = context.getId()
[5144]45session_id = context.getLevelSession(level.getContent(),student_id,level_id)
[2448]46res = context.portal_catalog(portal_type="Certificate", id = cert_id)
[2460]47query = Eq('student_id',student_id) & Eq('level_id', level_id)
[2758]48existing_courses = [course.code for course in
[2460]49                    context.course_results.evalAdvancedQuery(query)]
[2448]50l = []
[2460]51records = []
[2448]52if res:
53    cert = res[0]
54    path = cert.getPath()
[3074]55    if int(student.level) > 0:
56        academics_level = 100 * (int(student.level)/100)
57    else:
58        academics_level = '000'
[2758]59    query = Eq("path","%s/%s" % (path,academics_level)) &\
[2448]60            Eq('portal_type','CertificateCourse')
61    courses = aq_portal(query)
[2460]62    course_ids = [c.getId  for c in courses if c.getId not in existing_courses]
[2448]63    for course_id in course_ids:
64        #set_trace()
[2460]65        if course_id in l:
66            # don't add twice
67            continue
68        l += course_id,
[2448]69        d = context.getCourseInfo(course_id)
70        d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective')
71        d['course_id'] = course_id
[2758]72        d['student_id'] = student_id
73        d['level_id'] = level_id
[5144]74        d['session_id'] = session_id
[2448]75        d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
[2460]76        records.append(d)
77if records:
78    context.course_results.addMultipleRecords(records)
79
[2448]80#session.set('in_progress','finished')
[5144]81logger.info('%s updated level %s of %s' % (member,level_id,student_id))
[2448]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)
[2758]90return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.