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
|
---|
23 | logger = logging.getLogger('Skins.lecturer_course_edit')
|
---|
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()
|
---|
33 | if not 'Lecturers' in groups and not context.isSectionOfficer():
|
---|
34 | logger.info('%s tried to access course result record of %s but is not a lecturer' % (member_id,requested_id))
|
---|
35 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
36 |
|
---|
37 | student_id = requested_id
|
---|
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))
|
---|
41 | return 'Subject/course lists must be validated before editing results!'
|
---|
42 |
|
---|
43 |
|
---|
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 = {}
|
---|
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()
|
---|
57 | if str(lecturer_id) != member_id and not context.isSectionOfficer():
|
---|
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))
|
---|
59 | return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
60 |
|
---|
61 | for field in context.course_results.schema():
|
---|
62 | object[field] = getattr(course_result,field,None)
|
---|
63 | if repr(object[field]) == 'Missing.Value':
|
---|
64 | object[field] = None
|
---|
65 |
|
---|
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)
|
---|
89 | logger.info('%s edited course result %s of %s' % (member_id,course_id,student_id))
|
---|
90 | psm = 'psm_content_changed'
|
---|
91 | break
|
---|
92 | return context.lecturer_course_edit_form(rendered = res,
|
---|
93 | psm = psm,
|
---|
94 | mode = mode,
|
---|
95 | ds = ds,
|
---|
96 | )
|
---|