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

Last change on this file since 1851 was 1845, checked in by joachim, 18 years ago

modifications to use QueueCatalog?

  • 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=None
8##title=
9##
10# $Id: add_course_result.py 1845 2007-06-02 11:01:49Z joachim $
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')
32
33mtool = context.portal_membership
34member = mtool.getAuthenticatedMember()
35
36
37d = context.getCourseInfo(course_id)
38args = {}
39err = ''
40while True:
41    if d['title'] == 'unknown':
42        err = "No such course!"
43        #logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id))
44        break
45    if context.hasObject(course_id):
46        err = "Course already exists!"
47        #logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id))
48        break
49    if context.hasObject("%s_co" % course_id):
50        err = "Course already exists as carryover course!"
51        #logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id))
52        break
53    break
54
55if err:
56    args['course_id'] = course_id
57    #args['error'] = err
58    args['portal_status_message'] = err
59    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
60    return request.RESPONSE.redirect(url)
61
62
63cr_id = context.invokeFactory('StudentCourseResult',course_id)
64#set_trace()
65cr = getattr(context,cr_id)
66context.portal_workflow.doActionFor(cr,'open')
67cr.getContent().edit(mapping=d)
68context.portal_workflow.doActionFor(cr,'close')
69args['course_id'] = course_id
70
71logger.info('%s added StudentCourseResult object %s for %s' % (member,course_id,context.getStudentId()))
72
73psm = "You successfully added course %s!" % course_id
74args['portal_status_message'] = psm
75if action_after_validate:
76    url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args)
77else:
78    url = context.absolute_url() + '?' + urlencode(args)
79return REQUEST.RESPONSE.redirect(url)
80
Note: See TracBrowser for help on using the repository browser.