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 | """
|
---|
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.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 | member_id = str(member)
|
---|
30 | requested_id = context.getStudentId()
|
---|
31 | if 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())
|
---|
35 | elif context.isStaff():
|
---|
36 | student_id = requested_id
|
---|
37 | else:
|
---|
38 | student_id = member_id
|
---|
39 |
|
---|
40 | level_id = context.getId()
|
---|
41 | course_id = traverse_subpath[0]
|
---|
42 | query = Eq('student_id',student_id) &\
|
---|
43 | Eq('level_id', level_id) &\
|
---|
44 | Eq('code', course_id)
|
---|
45 |
|
---|
46 | course_results = context.course_results.evalAdvancedQuery(query)
|
---|
47 | mode = 'edit'
|
---|
48 | object = {}
|
---|
49 | course = course_results[0]
|
---|
50 | for field in context.course_results.schema():
|
---|
51 | object[field] = getattr(course,field)
|
---|
52 | lt = context.portal_layouts
|
---|
53 | res,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 |
|
---|
61 | while 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 |
|
---|
79 | return context.course_edit_form(rendered = res,
|
---|
80 | psm = psm,
|
---|
81 | mode = mode,
|
---|
82 | ds = ds,
|
---|
83 | )
|
---|
84 |
|
---|