[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 1863 2007-06-08 07:16:23Z joachim $ |
---|
[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 |
---|
[1845] | 27 | try: |
---|
| 28 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 29 | except: |
---|
| 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[1482] | 31 | course_id = request.get('course_id') |
---|
[1571] | 32 | mtool = context.portal_membership |
---|
| 33 | member = mtool.getAuthenticatedMember() |
---|
| 34 | |
---|
| 35 | |
---|
[1482] | 36 | d = context.getCourseInfo(course_id) |
---|
| 37 | args = {} |
---|
| 38 | err = '' |
---|
| 39 | while True: |
---|
[1858] | 40 | if not course_id: |
---|
| 41 | err = "Empty course id!" |
---|
| 42 | break |
---|
[1482] | 43 | if d['title'] == 'unknown': |
---|
[1571] | 44 | err = "No such course!" |
---|
[1648] | 45 | #logger.info('%s tried to add StudentCourseResult object %s for non-existing course' % (member,course_id)) |
---|
[1482] | 46 | break |
---|
| 47 | if context.hasObject(course_id): |
---|
[1571] | 48 | err = "Course already exists!" |
---|
[1648] | 49 | #logger.info('%s tried to add StudentCourseResult object %s which is already in course list' % (member,course_id)) |
---|
[1482] | 50 | break |
---|
| 51 | if context.hasObject("%s_co" % course_id): |
---|
[1571] | 52 | err = "Course already exists as carryover course!" |
---|
[1648] | 53 | #logger.info('%s tried to add StudentCourseResult object %s which already exists as carryover course' % (member,course_id)) |
---|
[1482] | 54 | break |
---|
| 55 | break |
---|
[731] | 56 | |
---|
[1482] | 57 | if err: |
---|
| 58 | args['course_id'] = course_id |
---|
[1571] | 59 | #args['error'] = err |
---|
| 60 | args['portal_status_message'] = err |
---|
[1600] | 61 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
[1482] | 62 | return request.RESPONSE.redirect(url) |
---|
[1571] | 63 | |
---|
[1590] | 64 | |
---|
[1482] | 65 | cr_id = context.invokeFactory('StudentCourseResult',course_id) |
---|
[1520] | 66 | #set_trace() |
---|
| 67 | cr = getattr(context,cr_id) |
---|
| 68 | context.portal_workflow.doActionFor(cr,'open') |
---|
| 69 | cr.getContent().edit(mapping=d) |
---|
[1863] | 70 | #context.portal_workflow.doActionFor(cr,'close') |
---|
[1482] | 71 | args['course_id'] = course_id |
---|
[1571] | 72 | |
---|
[1600] | 73 | logger.info('%s added StudentCourseResult object %s for %s' % (member,course_id,context.getStudentId())) |
---|
[1571] | 74 | |
---|
[1592] | 75 | psm = "You successfully added course %s!" % course_id |
---|
[1590] | 76 | args['portal_status_message'] = psm |
---|
[1606] | 77 | if action_after_validate: |
---|
| 78 | url = context.absolute_url() + '/' + action_after_validate + '?' + urlencode(args) |
---|
| 79 | else: |
---|
| 80 | url = context.absolute_url() + '?' + urlencode(args) |
---|
[1590] | 81 | return REQUEST.RESPONSE.redirect(url) |
---|
[1482] | 82 | |
---|