## 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 $ """ This method is for demonstration purposes only. There is noi security to deter lecturers from editing courses they are not allowed to edit. """ 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: logger.info('%s tried to access course result of %s' % (member_id,requested_id)) return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) student_id = requested_id 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 = course_results[0] for field in context.course_results.schema(): object[field] = getattr(course,field) 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 data %s' % (student_id, course_id)) psm = 'psm_content_changed' break return context.lecturer_course_edit_form(rendered = res, psm = psm, mode = mode, ds = ds, )