[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 | """
|
---|
[3617] | 11 | This method is for demonstration purposes only.
|
---|
[3611] | 12 | There is noi security to deter lecturers from editing courses they are not allowed to edit.
|
---|
| 13 | """
|
---|
| 14 | try:
|
---|
| 15 | from Products.zdb import set_trace
|
---|
| 16 | except:
|
---|
| 17 | def set_trace():
|
---|
| 18 | pass
|
---|
| 19 | from urllib import urlencode
|
---|
| 20 | from Products.CPSDocument.utils import getFormUidUrlArg
|
---|
| 21 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
| 22 | import DateTime
|
---|
| 23 | current = DateTime.DateTime()
|
---|
| 24 | import logging
|
---|
[3617] | 25 | logger = logging.getLogger('Skins.lecturer_course_edit')
|
---|
[3611] | 26 | wf = context.portal_workflow
|
---|
| 27 | request = REQUEST
|
---|
| 28 | edit = "edit" in request.form.keys()
|
---|
| 29 | mtool = context.portal_membership
|
---|
| 30 | member = mtool.getAuthenticatedMember()
|
---|
| 31 | groups = member.getGroups()
|
---|
| 32 |
|
---|
| 33 | member_id = str(member)
|
---|
| 34 | requested_id = context.getStudentId()
|
---|
| 35 | if not 'Lecturers' in groups:
|
---|
| 36 | logger.info('%s tried to access course result of %s' % (member_id,requested_id))
|
---|
| 37 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
| 38 |
|
---|
| 39 | student_id = requested_id
|
---|
| 40 |
|
---|
| 41 | level_id = context.getId()
|
---|
| 42 | course_id = traverse_subpath[0]
|
---|
| 43 | query = Eq('student_id',student_id) &\
|
---|
| 44 | Eq('level_id', level_id) &\
|
---|
| 45 | Eq('code', course_id)
|
---|
| 46 |
|
---|
| 47 | course_results = context.course_results.evalAdvancedQuery(query)
|
---|
| 48 | mode = 'edit'
|
---|
| 49 | object = {}
|
---|
| 50 | course = course_results[0]
|
---|
| 51 | for field in context.course_results.schema():
|
---|
| 52 | object[field] = getattr(course,field)
|
---|
| 53 | lt = context.portal_layouts
|
---|
| 54 | res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
|
---|
| 55 | layout_id = 'student_course_result',
|
---|
| 56 | layout_mode = mode,
|
---|
| 57 | context=context,
|
---|
| 58 | mapping=edit and REQUEST,
|
---|
| 59 | ob=object,
|
---|
| 60 | commit = False)
|
---|
| 61 |
|
---|
| 62 | while True:
|
---|
| 63 | if psm == 'invalid':
|
---|
| 64 | psm = "Please correct your input"
|
---|
| 65 | break
|
---|
| 66 | elif psm == '':
|
---|
| 67 | break
|
---|
| 68 | if edit:
|
---|
| 69 | data = {}
|
---|
| 70 | dm = ds.getDataModel()
|
---|
| 71 | for field in context.course_results.schema():
|
---|
| 72 | if dm.has_key("%s" % field):
|
---|
| 73 | data[field] = dm.get(field)
|
---|
| 74 | data['key'] = object['key']
|
---|
| 75 | context.course_results.modifyRecord(**data)
|
---|
| 76 | logger.info('%s edited course result data %s' % (student_id, course_id))
|
---|
| 77 | psm = 'psm_content_changed'
|
---|
| 78 | break
|
---|
| 79 |
|
---|
[3617] | 80 | return context.lecturer_course_edit_form(rendered = res,
|
---|
[3611] | 81 | psm = psm,
|
---|
| 82 | mode = mode,
|
---|
| 83 | ds = ds,
|
---|
| 84 | ) |
---|