source: WAeUP_SRP/trunk/skins/waeup_student/add_course_result.py @ 3786

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

fix logging message

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1## Script (Python) "add_course_result"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST=None, action_after_validate=''
8##title=
9##
10# $Id: add_course_result.py 3061 2008-01-29 09:41:44Z henrik $
11"""
12add a StudentCourseResult object
13"""
14
15import logging
16logger = logging.getLogger('Skins.add_course_result')
17
18from urllib import urlencode
19try:
20    from Products.zdb import set_trace
21except:
22    def set_trace():
23        pass
24request = context.REQUEST
25course_cat = context.courses_catalog
26from Products.AdvancedQuery import Eq, Between, Le,In
27try:
28    aq_portal = context.portal_catalog.evalAdvancedQuery
29except:
30    aq_portal = context.portal_catalog_real.evalAdvancedQuery
31course_id = request.get('course_id')
32mtool = context.portal_membership
33member = mtool.getAuthenticatedMember()
34
35d = context.getCourseInfo(course_id)
36args = {}
37err = ''
38d['core_or_elective'] = True
39while True:
40    if not course_id:
41        err = "Empty course id!"
42        break
43    if d['title'] == 'unknown':
44        err = "No such course!"
45        break
46    d['course_id'] = course_id
47    d['student_id'] = student_id = context.getStudentId()
48    d['level_id'] = level_id = context.getId()
49    session_id = context.getLevelSession(context.getContent(),student_id,level_id)
50    d['session_id'] = session_id
51    d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
52    try:
53        context.course_results.addRecord(**d)
54        break
55    except ValueError:
56        err = "Course already exists!"
57        break
58    break
59
60if err:
61    args['course_id'] = course_id
62    args['portal_status_message'] = err
63    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
64    return request.RESPONSE.redirect(url)
65
66
67logger.info('%s added course result record %s at level %s for %s' % (member,
68                                                                           course_id,
69                                                                           level_id,
70                                                                           student_id))
71
72psm = "You successfully added course %s!" % course_id
73args['portal_status_message'] = psm
74if action_after_validate:
75    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
76else:
77    url = context.absolute_url() + '?' + urlencode(args)
78return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.