source: WAeUP_SRP/base/skins/waeup_student/course_edit.py @ 3292

Last change on this file since 3292 was 2448, checked in by Henrik Bettermann, 17 years ago

new course registration module

File size: 2.8 KB
RevLine 
[2448]1## Script (Python) "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.course_edit')
24wf = context.portal_workflow
25request = REQUEST
26edit = "edit" in request.form.keys()
27mtool = context.portal_membership
28member = mtool.getAuthenticatedMember()
29member_id = str(member)
30requested_id = context.getStudentId()
31if requested_id and not context.isStaff() and member_id != requested_id:
32    logger.info('%s tried to access personal object of %s' % (member_id,requested_id))
33    student_id = requested_id
34    return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
35elif context.isStaff():
36    student_id = requested_id
37else:
38    student_id = member_id
39   
40level_id = context.getId()
41course_id = traverse_subpath[0]
42query = Eq('student_id',student_id) &\
43        Eq('level_id', level_id) &\
44        Eq('code', course_id)
45
46course_results = context.course_results.evalAdvancedQuery(query)
47mode = 'edit'
48object = {}
49course = course_results[0]
50for field in context.course_results.schema():
51    object[field] = getattr(course,field)
52lt = context.portal_layouts
53res,psm, ds = lt.renderLayout(schema_id = 'student_course_result',
54                               layout_id = 'student_course_result_fe',
55                               layout_mode = mode,
56                               context=context,
57                               mapping=edit and REQUEST,
58                               ob=object,
59                               commit = False)
60
61while True:
62    if psm == 'invalid':
63        psm = "Please correct your input"
64        break
65    elif psm == '':
66        break
67    if edit:
68        data = {}
69        dm = ds.getDataModel()
70        for field in context.course_results.schema():
71            if dm.has_key("%s" % field):
72                data[field] = dm.get(field)
73        data['key'] = object['key']
74        context.course_results.modifyRecord(**data)
75        logger.info('%s edited course result data %s' % (student_id, course_id))
76        psm = 'psm_content_changed'
77        break
78
79return context.course_edit_form(rendered = res,
80                                psm = psm,
81                                mode = mode,
82                                ds = ds,
83                               )
84
Note: See TracBrowser for help on using the repository browser.