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