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

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

some code cleaning

  • Property svn:keywords set to Id
File size: 2.3 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 5163 2010-04-21 04:38:00Z 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
27course_id = request.get('course_id')
28mtool = context.portal_membership
29member = mtool.getAuthenticatedMember()
30
31d = context.getCourseInfo(course_id)
32args = {}
33err = ''
34d['core_or_elective'] = True
35while True:
36    if not course_id:
37        err = "Empty course id!"
38        break
39    if d['title'] == 'unknown':
40        err = "No such course!"
41        break
42    d['course_id'] = course_id
43    d['student_id'] = student_id = context.getStudentId()
44    d['level_id'] = level_id = context.getId()
45    session_id = context.getLevelSession(context.getContent(),student_id,level_id)
46    d['session_id'] = session_id
47    d['key'] = "%s|%s|%s" % (student_id,level_id,course_id)
48    try:
49        context.course_results.addRecord(**d)
50        break
51    except ValueError:
52        err = "Course already exists!"
53        break
54    break
55
56if err:
57    args['course_id'] = course_id
58    args['portal_status_message'] = err
59    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
60    return request.RESPONSE.redirect(url)
61
62
63logger.info('%s added course result record %s at level %s for %s' % (member,
64                                                                           course_id,
65                                                                           level_id,
66                                                                           student_id))
67
68psm = "You successfully added course %s!" % course_id
69args['portal_status_message'] = psm
70if action_after_validate:
71    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
72else:
73    url = context.absolute_url() + '?' + urlencode(args)
74return REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.