[478] | 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= |
---|
[486] | 9 | # $Id: student_edit.py 535 2006-09-19 07:53:21Z joachim $ |
---|
[478] | 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 | |
---|
| 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 |
---|
[486] | 31 | #context.editLayouts(REQUEST=REQUEST) |
---|
[478] | 32 | |
---|
| 33 | # Validate the document and write it if it's valid |
---|
| 34 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
[535] | 35 | info = context.getStudentInfo() |
---|
[478] | 36 | |
---|
[535] | 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": |
---|
[523] | 43 | if state == "application_pin_entered": |
---|
[479] | 44 | student.content_status_modify(workflow_action="apply_for_admission") |
---|
[535] | 45 | if app_doc.passport is None: |
---|
| 46 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
| 47 | proxy=app_doc, |
---|
[479] | 48 | layout_id = "student_application_fe", |
---|
| 49 | layout_mode = 'edit', |
---|
| 50 | use_session=True) |
---|
[523] | 51 | |
---|
[535] | 52 | action = "/student_edit" |
---|
[479] | 53 | if is_valid: |
---|
[483] | 54 | psm = 'You successfully uploaded your passport image.' |
---|
[479] | 55 | args = {} |
---|
| 56 | else: |
---|
| 57 | psm = 'psm_content_error' |
---|
| 58 | args = getFormUidUrlArg(REQUEST) |
---|
[535] | 59 | elif 'apply_admission' not in REQUEST.form: |
---|
| 60 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
| 61 | proxy=app_doc, |
---|
| 62 | layout_id = "student_application_fe", |
---|
| 63 | layout_mode = 'edit', |
---|
| 64 | use_session=True) |
---|
| 65 | action = "/passport_entry_view" |
---|
| 66 | if is_valid: |
---|
| 67 | args = {} |
---|
| 68 | if 'apply_admission' not in REQUEST.form: |
---|
| 69 | args = {'apply_button': 'Save and Apply',} |
---|
| 70 | psm = 'You successfully uploaded your passport image.' |
---|
| 71 | else: |
---|
| 72 | psm = 'You applied for admission.' |
---|
| 73 | else: |
---|
| 74 | args = getFormUidUrlArg(REQUEST) |
---|
| 75 | #psm = 'psm_content_error' |
---|
| 76 | psm = '%s' % ds |
---|
[479] | 77 | else: |
---|
[482] | 78 | args = {} |
---|
[535] | 79 | psm = 'You applied for admission.' |
---|
| 80 | action = "/application_view" |
---|
[478] | 81 | else: |
---|
[535] | 82 | is_valid, ds = app_doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
[479] | 83 | use_session=True) |
---|
[483] | 84 | |
---|
[479] | 85 | if action is None: |
---|
[535] | 86 | ti = app.getTypeInfo() |
---|
[479] | 87 | action = ti.queryMethodID('edit', 'cpsdocument_edit_form') |
---|
| 88 | action = '/' + action |
---|
[483] | 89 | |
---|
[479] | 90 | if is_valid: |
---|
| 91 | comments = REQUEST.get('comments') |
---|
| 92 | context.cpsdocument_notify_modification(comments=comments) |
---|
| 93 | if cpsdocument_edit_and_view_button is not None: |
---|
| 94 | action = '' |
---|
| 95 | psm = 'psm_content_changed' |
---|
| 96 | args = {} |
---|
| 97 | else: |
---|
| 98 | psm = 'psm_content_error' |
---|
| 99 | args = getFormUidUrlArg(REQUEST) |
---|
[483] | 100 | |
---|
[478] | 101 | args['portal_status_message'] = psm |
---|
| 102 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
| 103 | REQUEST.RESPONSE.redirect(url) |
---|