source: WAeUP_SRP/base/skins/waeup_student/lecturer_course_edit.py @ 3611

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

implement lecturer module (for demo purposes only)

File size: 2.8 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"""
11This method is for demonstration purposes only.
12There is noi security to deter lecturers from editing courses they are not allowed to edit.
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19from urllib import urlencode
20from Products.CPSDocument.utils import getFormUidUrlArg
21from Products.AdvancedQuery import Eq, Between, Le,In
22import DateTime
23current = DateTime.DateTime()
24import logging
25logger = logging.getLogger('Skins.course_edit')
26wf = context.portal_workflow
27request = REQUEST
28edit = "edit" in request.form.keys()
29mtool = context.portal_membership
30member = mtool.getAuthenticatedMember()
31groups = member.getGroups()
32
33member_id = str(member)
34requested_id = context.getStudentId()
35if 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
39student_id = requested_id
40
41level_id = context.getId()
42course_id = traverse_subpath[0]
43query = Eq('student_id',student_id) &\
44        Eq('level_id', level_id) &\
45        Eq('code', course_id)
46
47course_results = context.course_results.evalAdvancedQuery(query)
48mode = 'edit'
49object = {}
50course = course_results[0]
51for field in context.course_results.schema():
52    object[field] = getattr(course,field)
53lt = context.portal_layouts
54res,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
62while 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
80return context.course_edit_form(rendered = res,
81                                psm = psm,
82                                mode = mode,
83                                ds = ds,
84                               )
Note: See TracBrowser for help on using the repository browser.