[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 770 2006-10-29 05:24:04Z henrik $ |
---|
[478] | 10 | """ |
---|
| 11 | """ |
---|
[539] | 12 | wftool = context.portal_workflow |
---|
[478] | 13 | from urllib import urlencode |
---|
| 14 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
[766] | 15 | import DateTime |
---|
| 16 | current = DateTime.DateTime() |
---|
[478] | 17 | |
---|
| 18 | # Until ajax posts directly to its own script... |
---|
| 19 | if 'ajax_edit' in REQUEST.form: |
---|
| 20 | return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster) |
---|
| 21 | |
---|
| 22 | # Check flexible controls |
---|
[486] | 23 | #context.editLayouts(REQUEST=REQUEST) |
---|
[478] | 24 | |
---|
| 25 | # Validate the document and write it if it's valid |
---|
| 26 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
[535] | 27 | info = context.getStudentInfo() |
---|
[478] | 28 | |
---|
[535] | 29 | student = info['student'] |
---|
| 30 | app = info['app'] |
---|
| 31 | app_doc = info['app_doc'] |
---|
[766] | 32 | clear = info['clear'] |
---|
| 33 | clear_doc = info['clear_doc'] |
---|
[535] | 34 | state = context.getStudentInfo()['review_state'] |
---|
| 35 | |
---|
| 36 | if context.portal_type == "Student": |
---|
| 37 | if app_doc.passport is None: |
---|
| 38 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
| 39 | proxy=app_doc, |
---|
[479] | 40 | layout_id = "student_application_fe", |
---|
| 41 | layout_mode = 'edit', |
---|
| 42 | use_session=True) |
---|
[770] | 43 | action = "/application_edit" |
---|
[710] | 44 | if is_valid: |
---|
| 45 | if app_doc.passport is not None: |
---|
| 46 | psm = 'You successfully uploaded your passport image.' |
---|
| 47 | args = {'apply_button': 'Apply',} |
---|
| 48 | else: |
---|
| 49 | psm = "You didn't upload a passport image." |
---|
| 50 | args = {} |
---|
[539] | 51 | else: |
---|
[710] | 52 | psm = 'psm_content_error' |
---|
| 53 | args = getFormUidUrlArg(REQUEST) |
---|
[535] | 54 | elif 'apply_admission' not in REQUEST.form: |
---|
| 55 | is_valid, ds = app_doc.validate(request=REQUEST, |
---|
| 56 | proxy=app_doc, |
---|
| 57 | layout_id = "student_application_fe", |
---|
| 58 | layout_mode = 'edit', |
---|
| 59 | use_session=True) |
---|
[770] | 60 | action = "/application_edit" |
---|
[535] | 61 | if is_valid: |
---|
| 62 | args = {} |
---|
| 63 | if 'apply_admission' not in REQUEST.form: |
---|
[541] | 64 | args = {'apply_button': 'Apply',} |
---|
[535] | 65 | psm = 'You successfully uploaded your passport image.' |
---|
| 66 | else: |
---|
| 67 | psm = 'You applied for admission.' |
---|
| 68 | else: |
---|
| 69 | args = getFormUidUrlArg(REQUEST) |
---|
[539] | 70 | psm = 'psm_content_error' |
---|
[479] | 71 | else: |
---|
[767] | 72 | psm = '' |
---|
[482] | 73 | args = {} |
---|
[766] | 74 | if info['review_state'] == "student_created": |
---|
| 75 | student.content_status_modify(workflow_action="apply_for_admission") |
---|
| 76 | wftool.doActionFor(app,'close',dest_container= app) |
---|
| 77 | psm = 'You applied for admission.' |
---|
| 78 | action = "/application_view" |
---|
[767] | 79 | elif info['review_state'] == "admitted": |
---|
| 80 | student.content_status_modify(workflow_action="enter_clearance_pin") |
---|
[766] | 81 | #wftool.doActionFor(info['clear'],'open',dest_container=info['clear']) |
---|
| 82 | app_doc = info['app_doc'] |
---|
| 83 | dc = {} |
---|
[770] | 84 | dc['email'] = app_doc.app_email |
---|
[766] | 85 | info['clear_doc'].edit(mapping = dc) |
---|
| 86 | wftool.doActionFor(app,'close',dest_container= app) |
---|
[767] | 87 | psm = 'You successfully started the clearance process.' |
---|
[770] | 88 | action = "/clearance_edit" |
---|
[766] | 89 | else: |
---|
| 90 | action = "/clearance_view" |
---|
[767] | 91 | |
---|
[478] | 92 | else: |
---|
[535] | 93 | is_valid, ds = app_doc.validate(request=REQUEST, proxy=context, cluster=cluster, |
---|
[479] | 94 | use_session=True) |
---|
[483] | 95 | |
---|
[479] | 96 | if action is None: |
---|
[535] | 97 | ti = app.getTypeInfo() |
---|
[479] | 98 | action = ti.queryMethodID('edit', 'cpsdocument_edit_form') |
---|
| 99 | action = '/' + action |
---|
[483] | 100 | |
---|
[479] | 101 | if is_valid: |
---|
| 102 | comments = REQUEST.get('comments') |
---|
| 103 | context.cpsdocument_notify_modification(comments=comments) |
---|
| 104 | if cpsdocument_edit_and_view_button is not None: |
---|
| 105 | action = '' |
---|
| 106 | psm = 'psm_content_changed' |
---|
| 107 | args = {} |
---|
| 108 | else: |
---|
| 109 | psm = 'psm_content_error' |
---|
| 110 | args = getFormUidUrlArg(REQUEST) |
---|
[483] | 111 | |
---|
[478] | 112 | args['portal_status_message'] = psm |
---|
| 113 | url = context.absolute_url() + action + '?' + urlencode(args) |
---|
| 114 | REQUEST.RESPONSE.redirect(url) |
---|