[2448] | 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 | """
|
---|
| 12 | add a StudentCourseResult object
|
---|
| 13 | """
|
---|
| 14 |
|
---|
| 15 | import logging
|
---|
| 16 | logger = logging.getLogger('Skins.add_course_result')
|
---|
| 17 |
|
---|
| 18 | from urllib import urlencode
|
---|
| 19 | try:
|
---|
| 20 | from Products.zdb import set_trace
|
---|
| 21 | except:
|
---|
| 22 | def set_trace():
|
---|
| 23 | pass
|
---|
| 24 | request = context.REQUEST
|
---|
| 25 | course_cat = context.courses_catalog
|
---|
| 26 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 27 | course_id = request.get('course_id')
|
---|
| 28 | mtool = context.portal_membership
|
---|
| 29 | member = mtool.getAuthenticatedMember()
|
---|
| 30 |
|
---|
| 31 | d = context.getCourseInfo(course_id)
|
---|
| 32 | args = {}
|
---|
| 33 | err = ''
|
---|
| 34 | d['core_or_elective'] = True
|
---|
| 35 | while 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
|
---|
[2460] | 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:
|
---|
[2448] | 52 | err = "Course already exists!"
|
---|
| 53 | break
|
---|
| 54 | break
|
---|
| 55 |
|
---|
| 56 | if 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 |
|
---|
[3061] | 63 | logger.info('%s added course result record %s at level %s for %s' % (member,
|
---|
[2448] | 64 | course_id,
|
---|
| 65 | level_id,
|
---|
| 66 | student_id))
|
---|
| 67 |
|
---|
| 68 | psm = "You successfully added course %s!" % course_id
|
---|
| 69 | args['portal_status_message'] = psm
|
---|
| 70 | if action_after_validate:
|
---|
| 71 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
|
---|
| 72 | else:
|
---|
| 73 | url = context.absolute_url() + '?' + urlencode(args)
|
---|
[3061] | 74 | return REQUEST.RESPONSE.redirect(url) |
---|