[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 |
---|
[1590] | 7 | ##parameters=REQUEST=None, action_after_validate=None |
---|
[731] | 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: add_course_result.py 1606 2007-03-20 09:22:20Z henrik $ |
---|
[731] | 11 | """ |
---|
[1519] | 12 | add a StudentCourseResult object |
---|
[731] | 13 | """ |
---|
[1571] | 14 | |
---|
| 15 | import logging |
---|
| 16 | logger = logging.getLogger('Skins.add_course_result') |
---|
| 17 | |
---|
[1482] | 18 | from urllib import urlencode |
---|
[1520] | 19 | try: |
---|
| 20 | from Products.zdb import set_trace |
---|
| 21 | except: |
---|
| 22 | def set_trace(): |
---|
| 23 | pass |
---|
[1592] | 24 | request = context.REQUEST |
---|
[1482] | 25 | course_cat = context.courses_catalog |
---|
| 26 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 27 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 28 | course_id = request.get('course_id') |
---|
[1571] | 29 | |
---|
| 30 | mtool = context.portal_membership |
---|
| 31 | member = mtool.getAuthenticatedMember() |
---|
| 32 | |
---|
| 33 | |
---|
[1482] | 34 | d = context.getCourseInfo(course_id) |
---|
| 35 | args = {} |
---|
| 36 | err = '' |
---|
| 37 | while True: |
---|
| 38 | if d['title'] == 'unknown': |
---|
[1571] | 39 | err = "No such course!" |
---|
| 40 | logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id)) |
---|
[1482] | 41 | break |
---|
| 42 | if context.hasObject(course_id): |
---|
[1571] | 43 | err = "Course already exists!" |
---|
| 44 | logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id)) |
---|
[1482] | 45 | break |
---|
| 46 | if context.hasObject("%s_co" % course_id): |
---|
[1571] | 47 | err = "Course already exists as carryover course!" |
---|
| 48 | logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id)) |
---|
[1482] | 49 | break |
---|
| 50 | break |
---|
[731] | 51 | |
---|
[1482] | 52 | if err: |
---|
| 53 | args['course_id'] = course_id |
---|
[1571] | 54 | #args['error'] = err |
---|
| 55 | args['portal_status_message'] = err |
---|
[1600] | 56 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
[1482] | 57 | return request.RESPONSE.redirect(url) |
---|
[1571] | 58 | |
---|
[1590] | 59 | |
---|
[1482] | 60 | cr_id = context.invokeFactory('StudentCourseResult',course_id) |
---|
[1520] | 61 | #set_trace() |
---|
| 62 | cr = getattr(context,cr_id) |
---|
| 63 | context.portal_workflow.doActionFor(cr,'open') |
---|
| 64 | cr.getContent().edit(mapping=d) |
---|
| 65 | context.portal_workflow.doActionFor(cr,'close') |
---|
[1482] | 66 | args['course_id'] = course_id |
---|
[1571] | 67 | |
---|
[1600] | 68 | logger.info('%s added StudentCourseResult object %s for %s' % (member,course_id,context.getStudentId())) |
---|
[1571] | 69 | |
---|
[1592] | 70 | psm = "You successfully added course %s!" % course_id |
---|
[1590] | 71 | args['portal_status_message'] = psm |
---|
[1606] | 72 | if action_after_validate: |
---|
| 73 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
| 74 | else: |
---|
| 75 | url = context.absolute_url() + '?' + urlencode(args) |
---|
[1590] | 76 | return REQUEST.RESPONSE.redirect(url) |
---|
[1482] | 77 | |
---|