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 | # $Id: student_edit.py 710 2006-10-16 22:30:16Z joachim $ |
---|
10 | """ |
---|
11 | Called when a document form is posted. |
---|
12 | |
---|
13 | Validates data, then: |
---|
14 | |
---|
15 | - if there's no error, updates the object and redirects to it, |
---|
16 | |
---|
17 | - if there's an error, puts data in session and redirects to edit form. |
---|
18 | |
---|
19 | A form uid is propagated during the redirect to uniquely identify the |
---|
20 | form in the session. |
---|
21 | """ |
---|
22 | wftool = context.portal_workflow |
---|
23 | from urllib import urlencode |
---|
24 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
25 | |
---|
26 | # Until ajax posts directly to its own script... |
---|
27 | if 'ajax_edit' in REQUEST.form: |
---|
28 | return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster) |
---|
29 | |
---|
30 | # Check flexible controls |
---|
31 | #context.editLayouts(REQUEST=REQUEST) |
---|
32 | |
---|
33 | # Validate the document and write it if it's valid |
---|
34 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
35 | info = context.getStudentInfo() |
---|
36 | |
---|
37 | student = info['student'] |
---|
38 | app = info['app'] |
---|
39 | app_doc = info['app_doc'] |
---|
40 | state = context.getStudentInfo()['review_state'] |
---|
41 | |
---|
42 | if context.portal_type == "Student": |
---|
43 | if app_doc.passport is None: |
---|
44 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
45 | proxy=app_doc, |
---|
46 | layout_id = "student_application_fe", |
---|
47 | layout_mode = 'edit', |
---|
48 | use_session=True) |
---|
49 | action = "/passport_entry_view" |
---|
50 | if is_valid: |
---|
51 | if app_doc.passport is not None: |
---|
52 | psm = 'You successfully uploaded your passport image.' |
---|
53 | args = {'apply_button': 'Apply',} |
---|
54 | else: |
---|
55 | psm = "You didn't upload a passport image." |
---|
56 | args = {} |
---|
57 | else: |
---|
58 | psm = 'psm_content_error' |
---|
59 | args = getFormUidUrlArg(REQUEST) |
---|
60 | elif 'apply_admission' not in REQUEST.form: |
---|
61 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
62 | proxy=app_doc, |
---|
63 | layout_id = "student_application_fe", |
---|
64 | layout_mode = 'edit', |
---|
65 | use_session=True) |
---|
66 | action = "/passport_entry_view" |
---|
67 | if is_valid: |
---|
68 | args = {} |
---|
69 | if 'apply_admission' not in REQUEST.form: |
---|
70 | args = {'apply_button': 'Apply',} |
---|
71 | psm = 'You successfully uploaded your passport image.' |
---|
72 | else: |
---|
73 | psm = 'You applied for admission.' |
---|
74 | else: |
---|
75 | args = getFormUidUrlArg(REQUEST) |
---|
76 | psm = 'psm_content_error' |
---|
77 | else: |
---|
78 | args = {} |
---|
79 | student.content_status_modify(workflow_action="apply_for_admission") |
---|
80 | wftool.doActionFor(app,'close',dest_container= app) |
---|
81 | psm = 'You applied for admission.' |
---|
82 | action = "/application_view" |
---|
83 | else: |
---|
84 | is_valid, ds = app_doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
85 | use_session=True) |
---|
86 | |
---|
87 | if action is None: |
---|
88 | ti = app.getTypeInfo() |
---|
89 | action = ti.queryMethodID('edit', 'cpsdocument_edit_form') |
---|
90 | action = '/' + action |
---|
91 | |
---|
92 | if is_valid: |
---|
93 | comments = REQUEST.get('comments') |
---|
94 | context.cpsdocument_notify_modification(comments=comments) |
---|
95 | if cpsdocument_edit_and_view_button is not None: |
---|
96 | action = '' |
---|
97 | psm = 'psm_content_changed' |
---|
98 | args = {} |
---|
99 | else: |
---|
100 | psm = 'psm_content_error' |
---|
101 | args = getFormUidUrlArg(REQUEST) |
---|
102 | |
---|
103 | args['portal_status_message'] = psm |
---|
104 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
105 | REQUEST.RESPONSE.redirect(url) |
---|