[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():
|
---|
[4033] | 34 | logger.info('%s tried to access course result record 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
|
---|
[4033] | 38 | student_record = context.students_catalog.getRecordByKey(student_id)
|
---|
| 39 | if student_record.review_state != 'courses_validated':
|
---|
| 40 | logger.info('%s tried to access non-validated course result record of %s' % (member_id,requested_id))
|
---|
[4043] | 41 | return 'Subject/course lists must be validated before editing results!'
|
---|
[3611] | 42 |
|
---|
[4033] | 43 |
|
---|
[3611] | 44 | level_id = context.getId()
|
---|
| 45 | course_id = traverse_subpath[0]
|
---|
| 46 | query = Eq('student_id',student_id) &\
|
---|
| 47 | Eq('level_id', level_id) &\
|
---|
| 48 | Eq('code', course_id)
|
---|
| 49 |
|
---|
| 50 | course_results = context.course_results.evalAdvancedQuery(query)
|
---|
| 51 | mode = 'edit'
|
---|
| 52 | object = {}
|
---|
[3818] | 53 | course_result = course_results[0]
|
---|
| 54 | course = context.courses_catalog(code=course_id)[0]
|
---|
| 55 | lecturer_id = getattr(course,'lecturer',None)
|
---|
| 56 | #set_trace()
|
---|
[4300] | 57 | if member_id not in str(lecturer_id) and not context.isSectionOfficer():
|
---|
[4033] | 58 | logger.info('%s tried to access course result record %s of %s but is not a lecturer of this course' % (member_id,course_id,requested_id))
|
---|
[3818] | 59 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
| 60 |
|
---|
[3611] | 61 | for field in context.course_results.schema():
|
---|
[3818] | 62 | object[field] = getattr(course_result,field,None)
|
---|
[3707] | 63 | if repr(object[field]) == 'Missing.Value':
|
---|
| 64 | object[field] = None
|
---|
[3818] | 65 |
|
---|
[3611] | 66 | lt = context.portal_layouts
|
---|
| 67 | res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
|
---|
| 68 | layout_id = 'student_course_result',
|
---|
| 69 | layout_mode = mode,
|
---|
| 70 | context=context,
|
---|
| 71 | mapping=edit and REQUEST,
|
---|
| 72 | ob=object,
|
---|
| 73 | commit = False)
|
---|
| 74 |
|
---|
| 75 | while True:
|
---|
| 76 | if psm == 'invalid':
|
---|
| 77 | psm = "Please correct your input"
|
---|
| 78 | break
|
---|
| 79 | elif psm == '':
|
---|
| 80 | break
|
---|
| 81 | if edit:
|
---|
| 82 | data = {}
|
---|
| 83 | dm = ds.getDataModel()
|
---|
| 84 | for field in context.course_results.schema():
|
---|
| 85 | if dm.has_key("%s" % field):
|
---|
| 86 | data[field] = dm.get(field)
|
---|
| 87 | data['key'] = object['key']
|
---|
| 88 | context.course_results.modifyRecord(**data)
|
---|
[3786] | 89 | logger.info('%s edited course result %s of %s' % (member_id,course_id,student_id))
|
---|
[3611] | 90 | psm = 'psm_content_changed'
|
---|
| 91 | break
|
---|
[3617] | 92 | return context.lecturer_course_edit_form(rendered = res,
|
---|
[3611] | 93 | psm = psm,
|
---|
| 94 | mode = mode,
|
---|
| 95 | ds = ds,
|
---|
[4043] | 96 | )
|
---|