1 | ## Script (Python) "register_courses" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST=None, student=None, action_after_reject=None, action_after_validate=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: register_courses.py 1504 2007-02-26 21:20:40Z henrik $ |
---|
11 | """ |
---|
12 | close the Students StudyLevel |
---|
13 | """ |
---|
14 | from Products.CMFCore.WorkflowCore import WorkflowException |
---|
15 | try: |
---|
16 | from Products.zdb import set_trace |
---|
17 | except: |
---|
18 | def set_trace(): |
---|
19 | pass |
---|
20 | |
---|
21 | from urllib import urlencode |
---|
22 | |
---|
23 | request = context.REQUEST |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | member_id = str(member) |
---|
27 | import logging |
---|
28 | logger = logging.getLogger('Skins.register_courses') |
---|
29 | |
---|
30 | wftool = context.portal_workflow |
---|
31 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
32 | student_id = context.getStudentId() |
---|
33 | student = getattr(students_folder,student_id) |
---|
34 | |
---|
35 | info = context.getStudyLevelInfo() |
---|
36 | if info['credits_exceeded']: |
---|
37 | args = {} |
---|
38 | args['portal_status_message'] = "Your total credits exceed %s!" % info['max_credits'] |
---|
39 | url = context.absolute_url() + '?' + urlencode(args) |
---|
40 | logger.info('%s tried to register course list with credits exceeded, probably by pressing the browser back button' % (student_id)) |
---|
41 | return REQUEST.RESPONSE.redirect(url) |
---|
42 | |
---|
43 | try: |
---|
44 | wftool.doActionFor(student,'register_courses') |
---|
45 | except WorkflowException,E: |
---|
46 | logger.info('%s WorkflowException %s for %s' % (member_id,E,student_id)) |
---|
47 | return request.RESPONSE.redirect("%s" % context.absolute_url()) |
---|
48 | |
---|
49 | try: |
---|
50 | wftool.doActionFor(context,'close') |
---|
51 | except WorkflowException,E: |
---|
52 | #logger.info('%s WorkflowException %s for %s' % (member_id,E,student_id)) |
---|
53 | #return request.RESPONSE.redirect("%s" % context.absolute_url()) |
---|
54 | pass |
---|
55 | |
---|
56 | logger.info('%s registered course list of %s' % (member_id,student_id)) |
---|
57 | args = {} |
---|
58 | psm = "You successfully submitted your course list!" |
---|
59 | args['portal_status_message'] = psm |
---|
60 | if action_after_validate: |
---|
61 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
62 | else: |
---|
63 | url = context.absolute_url() + '?' + urlencode(args) |
---|
64 | return REQUEST.RESPONSE.redirect(url) |
---|