source: WAeUP_SRP/trunk/skins/waeup_student/lecturer_course_edit.py @ 17977

Last change on this file since 17977 was 4300, checked in by Henrik Bettermann, 16 years ago

resolve schools #7 and more ...

File size: 3.6 KB
Line 
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"""
12try:
13    from Products.zdb import set_trace
14except:
15    def set_trace():
16        pass
17from urllib import urlencode
18from Products.CPSDocument.utils import getFormUidUrlArg
19from Products.AdvancedQuery import Eq, Between, Le,In
20import DateTime
21current = DateTime.DateTime()
22import logging
23logger = logging.getLogger('Skins.lecturer_course_edit')
24wf = context.portal_workflow
25request = REQUEST
26edit = "edit" in request.form.keys()
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29groups = member.getGroups()
30
31member_id = str(member)
32requested_id = context.getStudentId()
33if 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
37student_id = requested_id
38student_record = context.students_catalog.getRecordByKey(student_id)
39if 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
44level_id = context.getId()
45course_id = traverse_subpath[0]
46query = Eq('student_id',student_id) &\
47        Eq('level_id', level_id) &\
48        Eq('code', course_id)
49
50course_results = context.course_results.evalAdvancedQuery(query)
51mode = 'edit'
52object = {}
53course_result = course_results[0]
54course = context.courses_catalog(code=course_id)[0]
55lecturer_id = getattr(course,'lecturer',None)
56#set_trace()
57if  member_id not in str(lecturer_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
61for 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     
66lt = context.portal_layouts
67res,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
75while 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
92return context.lecturer_course_edit_form(rendered = res,
93                                psm = psm,
94                                mode = mode,
95                                ds = ds,
96                               )
Note: See TracBrowser for help on using the repository browser.