1 | ## Script (Python) "cpsdocument_edit" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST, cluster=None, cpsdocument_edit_and_view_button=None, action=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: cpsdocument_edit.py 33302 2006-02-22 15:57:11Z tziade $ |
---|
11 | """ |
---|
12 | Called when a document form is posted. |
---|
13 | |
---|
14 | Validates data, then: |
---|
15 | |
---|
16 | - if there's no error, updates the object and redirects to it, |
---|
17 | |
---|
18 | - if there's an error, puts data in session and redirects to edit form. |
---|
19 | |
---|
20 | A form uid is propagated during the redirect to uniquely identify the |
---|
21 | form in the session. |
---|
22 | """ |
---|
23 | |
---|
24 | from urllib import urlencode |
---|
25 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
26 | |
---|
27 | # Until ajax posts directly to its own script... |
---|
28 | if 'ajax_edit' in REQUEST.form: |
---|
29 | return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster) |
---|
30 | |
---|
31 | # Check flexible controls |
---|
32 | context.editLayouts(REQUEST=REQUEST) |
---|
33 | |
---|
34 | # Validate the document and write it if it's valid |
---|
35 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
36 | info = context.getStudentInfo() |
---|
37 | if info and info['is_student']: |
---|
38 | return |
---|
39 | doc = context.getContent() |
---|
40 | is_valid, ds = doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
41 | use_session=True) |
---|
42 | |
---|
43 | if action is None: |
---|
44 | ti = doc.getTypeInfo() |
---|
45 | action = ti.queryMethodID('edit', 'cpsdocument_edit_form') |
---|
46 | action = '/' + action |
---|
47 | |
---|
48 | if is_valid: |
---|
49 | comments = REQUEST.get('comments') |
---|
50 | context.cpsdocument_notify_modification(comments=comments) |
---|
51 | if cpsdocument_edit_and_view_button is not None: |
---|
52 | action = '' |
---|
53 | psm = 'psm_content_changed' |
---|
54 | args = {} |
---|
55 | else: |
---|
56 | psm = 'psm_content_error' |
---|
57 | args = getFormUidUrlArg(REQUEST) |
---|
58 | |
---|
59 | args['portal_status_message'] = psm |
---|
60 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
61 | REQUEST.RESPONSE.redirect(url) |
---|