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

Last change on this file since 2210 was 2033, checked in by joachim, 17 years ago

add course too registered_courses only for current_level

  • Property svn:keywords set to Id
File size: 2.7 KB
RevLine 
[1519]1## Script (Python) "add_course_result"
[731]2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[1852]7##parameters=REQUEST=None, action_after_validate=''
[731]8##title=
9##
[805]10# $Id: add_course_result.py 2033 2007-07-18 13:44:13Z joachim $
[731]11"""
[1519]12add a StudentCourseResult object
[731]13"""
[1571]14
15import logging
16logger = logging.getLogger('Skins.add_course_result')
17
[1482]18from urllib import urlencode
[1520]19try:
20    from Products.zdb import set_trace
21except:
22    def set_trace():
23        pass
[1592]24request = context.REQUEST
[1482]25course_cat = context.courses_catalog
26from Products.AdvancedQuery import Eq, Between, Le,In
[1845]27try:
28    aq_portal = context.portal_catalog.evalAdvancedQuery
29except:
30    aq_portal = context.portal_catalog_real.evalAdvancedQuery
[1482]31course_id = request.get('course_id')
[1571]32mtool = context.portal_membership
33member = mtool.getAuthenticatedMember()
34
35
[1482]36d = context.getCourseInfo(course_id)
37args = {}
38err = ''
[1971]39d['core_or_elective'] = True
[1482]40while True:
[1858]41    if not course_id:
42        err = "Empty course id!"
43        break
[1482]44    if d['title'] == 'unknown':
[1571]45        err = "No such course!"
[1648]46        #logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id))
[1482]47        break
48    if context.hasObject(course_id):
[1571]49        err = "Course already exists!"
[1648]50        #logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id))
[1482]51        break
52    if context.hasObject("%s_co" % course_id):
[1571]53        err = "Course already exists as carryover course!"
[1648]54        #logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id))
[1482]55        break
56    break
[731]57
[1482]58if err:
59    args['course_id'] = course_id
[1571]60    #args['error'] = err
61    args['portal_status_message'] = err
[1600]62    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
[1482]63    return request.RESPONSE.redirect(url)
[1571]64
[1590]65
[1482]66cr_id = context.invokeFactory('StudentCourseResult',course_id)
[1520]67cr = getattr(context,cr_id)
68context.portal_workflow.doActionFor(cr,'open')
69cr.getContent().edit(mapping=d)
[1896]70#context.portal_workflow.doActionFor(cr,'close')
[2033]71#args['course_id'] = course_id
[1571]72
[2033]73logger.info('%s added StudentCourseResult object %s at level %s for %s' % (member,
74                                                                           course_id,
75                                                                           context.getId(),
76                                                                           context.getStudentId()))
[1571]77
[1592]78psm = "You successfully added course %s!" % course_id
[1590]79args['portal_status_message'] = psm
[1606]80if action_after_validate:
81    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
82else:
83    url = context.absolute_url() + '?' + urlencode(args)
[1590]84return REQUEST.RESPONSE.redirect(url)
[1482]85
Note: See TracBrowser for help on using the repository browser.