## Script (Python) "lecturer_course_edit" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST, cpsdocument_edit_button=None, cpsdocument_edit_and_view_button=None, action=None ##title= # $Id: course_edit.py 1071 2006-12-16 15:53:13Z joachim $ """ """ try: from Products.zdb import set_trace except: def set_trace(): pass from urllib import urlencode from Products.CPSDocument.utils import getFormUidUrlArg from Products.AdvancedQuery import Eq, Between, Le,In import DateTime current = DateTime.DateTime() import logging logger = logging.getLogger('Skins.lecturer_course_edit') wf = context.portal_workflow request = REQUEST edit = "edit" in request.form.keys() mtool = context.portal_membership member = mtool.getAuthenticatedMember() groups = member.getGroups() member_id = str(member) requested_id = context.getStudentId() if not 'Lecturers' in groups and not context.isSectionOfficer(): logger.info('%s tried to access course result record of %s but is not a lecturer' % (member_id,requested_id)) return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) student_id = requested_id student_record = context.students_catalog.getRecordByKey(student_id) if student_record.review_state != 'courses_validated': logger.info('%s tried to access non-validated course result record of %s' % (member_id,requested_id)) return 'Subject/course lists must be validated before editing results!' level_id = context.getId() course_id = traverse_subpath[0] query = Eq('student_id',student_id) &\ Eq('level_id', level_id) &\ Eq('code', course_id) course_results = context.course_results.evalAdvancedQuery(query) mode = 'edit' object = {} course_result = course_results[0] course = context.courses_catalog(code=course_id)[0] lecturer_id = getattr(course,'lecturer',None) #set_trace() if str(lecturer_id) != member_id and not context.isSectionOfficer(): 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)) return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) for field in context.course_results.schema(): object[field] = getattr(course_result,field,None) if repr(object[field]) == 'Missing.Value': object[field] = None lt = context.portal_layouts res,psm, ds = lt.renderLayout(schema_id = 'student_course_result', layout_id = 'student_course_result', layout_mode = mode, context=context, mapping=edit and REQUEST, ob=object, commit = False) while True: if psm == 'invalid': psm = "Please correct your input" break elif psm == '': break if edit: data = {} dm = ds.getDataModel() for field in context.course_results.schema(): if dm.has_key("%s" % field): data[field] = dm.get(field) data['key'] = object['key'] context.course_results.modifyRecord(**data) logger.info('%s edited course result %s of %s' % (member_id,course_id,student_id)) psm = 'psm_content_changed' break return context.lecturer_course_edit_form(rendered = res, psm = psm, mode = mode, ds = ds, )