[3611] | 1 | ## Script (Python) "lecturer_course_edit"
|
---|
| 2 | ##bind container=container
|
---|
| 3 | ##bind context=context
|
---|
| 4 | ##bind namespace=
|
---|
| 5 | ##bind script=script
|
---|
| 6 | ##bind subpath=traverse_subpath
|
---|
| 7 | ##parameters=REQUEST, cpsdocument_edit_button=None, cpsdocument_edit_and_view_button=None, action=None
|
---|
| 8 | ##title=
|
---|
| 9 | # $Id: course_edit.py 1071 2006-12-16 15:53:13Z joachim $
|
---|
| 10 | """
|
---|
| 11 | """
|
---|
| 12 | try:
|
---|
| 13 | from Products.zdb import set_trace
|
---|
| 14 | except:
|
---|
| 15 | def set_trace():
|
---|
| 16 | pass
|
---|
| 17 | from urllib import urlencode
|
---|
| 18 | from Products.CPSDocument.utils import getFormUidUrlArg
|
---|
| 19 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 20 | import DateTime
|
---|
| 21 | current = DateTime.DateTime()
|
---|
| 22 | import logging
|
---|
[3617] | 23 | logger = logging.getLogger('Skins.lecturer_course_edit')
|
---|
[3611] | 24 | wf = context.portal_workflow
|
---|
| 25 | request = REQUEST
|
---|
| 26 | edit = "edit" in request.form.keys()
|
---|
| 27 | mtool = context.portal_membership
|
---|
| 28 | member = mtool.getAuthenticatedMember()
|
---|
| 29 | groups = member.getGroups()
|
---|
| 30 |
|
---|
| 31 | member_id = str(member)
|
---|
| 32 | requested_id = context.getStudentId()
|
---|
[3752] | 33 | if not 'Lecturers' in groups and not context.isSectionOfficer():
|
---|
[3818] | 34 | logger.info('%s tried to access course result of %s but is not a lecturer' % (member_id,requested_id))
|
---|
[3611] | 35 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
| 36 |
|
---|
| 37 | student_id = requested_id
|
---|
| 38 |
|
---|
| 39 | level_id = context.getId()
|
---|
| 40 | course_id = traverse_subpath[0]
|
---|
| 41 | query = Eq('student_id',student_id) &\
|
---|
| 42 | Eq('level_id', level_id) &\
|
---|
| 43 | Eq('code', course_id)
|
---|
| 44 |
|
---|
| 45 | course_results = context.course_results.evalAdvancedQuery(query)
|
---|
| 46 | mode = 'edit'
|
---|
| 47 | object = {}
|
---|
[3818] | 48 | course_result = course_results[0]
|
---|
| 49 | course = context.courses_catalog(code=course_id)[0]
|
---|
| 50 | lecturer_id = getattr(course,'lecturer',None)
|
---|
| 51 | #set_trace()
|
---|
[3820] | 52 | if str(lecturer_id) != member_id and not context.isSectionOfficer():
|
---|
[3818] | 53 | logger.info('%s tried to access course result %s of %s but is not a lecturer of this course' % (member_id,course_id,requested_id))
|
---|
| 54 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
| 55 |
|
---|
[3611] | 56 | for field in context.course_results.schema():
|
---|
[3818] | 57 | object[field] = getattr(course_result,field,None)
|
---|
[3707] | 58 | if repr(object[field]) == 'Missing.Value':
|
---|
| 59 | object[field] = None
|
---|
[3818] | 60 |
|
---|
[3611] | 61 | lt = context.portal_layouts
|
---|
| 62 | res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
|
---|
| 63 | layout_id = 'student_course_result',
|
---|
| 64 | layout_mode = mode,
|
---|
| 65 | context=context,
|
---|
| 66 | mapping=edit and REQUEST,
|
---|
| 67 | ob=object,
|
---|
| 68 | commit = False)
|
---|
| 69 |
|
---|
| 70 | while True:
|
---|
| 71 | if psm == 'invalid':
|
---|
| 72 | psm = "Please correct your input"
|
---|
| 73 | break
|
---|
| 74 | elif psm == '':
|
---|
| 75 | break
|
---|
| 76 | if edit:
|
---|
| 77 | data = {}
|
---|
| 78 | dm = ds.getDataModel()
|
---|
| 79 | for field in context.course_results.schema():
|
---|
| 80 | if dm.has_key("%s" % field):
|
---|
| 81 | data[field] = dm.get(field)
|
---|
| 82 | data['key'] = object['key']
|
---|
| 83 | context.course_results.modifyRecord(**data)
|
---|
[3786] | 84 | logger.info('%s edited course result %s of %s' % (member_id,course_id,student_id))
|
---|
[3611] | 85 | psm = 'psm_content_changed'
|
---|
| 86 | break
|
---|
[3617] | 87 | return context.lecturer_course_edit_form(rendered = res,
|
---|
[3611] | 88 | psm = psm,
|
---|
| 89 | mode = mode,
|
---|
| 90 | ds = ds,
|
---|
| 91 | ) |
---|