[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()
|
---|
[3752] | 35 | if not 'Lecturers' in groups and not context.isSectionOfficer():
|
---|
[3611] | 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():
|
---|
[3707] | 52 | object[field] = getattr(course,field,None)
|
---|
| 53 | if repr(object[field]) == 'Missing.Value':
|
---|
| 54 | object[field] = None
|
---|
| 55 | #set_trace()
|
---|
[3611] | 56 | lt = context.portal_layouts
|
---|
| 57 | res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
|
---|
| 58 | layout_id = 'student_course_result',
|
---|
| 59 | layout_mode = mode,
|
---|
| 60 | context=context,
|
---|
| 61 | mapping=edit and REQUEST,
|
---|
| 62 | ob=object,
|
---|
| 63 | commit = False)
|
---|
| 64 |
|
---|
| 65 | while True:
|
---|
| 66 | if psm == 'invalid':
|
---|
| 67 | psm = "Please correct your input"
|
---|
| 68 | break
|
---|
| 69 | elif psm == '':
|
---|
| 70 | break
|
---|
| 71 | if edit:
|
---|
| 72 | data = {}
|
---|
| 73 | dm = ds.getDataModel()
|
---|
| 74 | for field in context.course_results.schema():
|
---|
| 75 | if dm.has_key("%s" % field):
|
---|
| 76 | data[field] = dm.get(field)
|
---|
| 77 | data['key'] = object['key']
|
---|
| 78 | context.course_results.modifyRecord(**data)
|
---|
| 79 | logger.info('%s edited course result data %s' % (student_id, course_id))
|
---|
| 80 | psm = 'psm_content_changed'
|
---|
| 81 | break
|
---|
[3617] | 82 | return context.lecturer_course_edit_form(rendered = res,
|
---|
[3611] | 83 | psm = psm,
|
---|
| 84 | mode = mode,
|
---|
| 85 | ds = ds,
|
---|
| 86 | ) |
---|