[845] | 1 | ## Script (Python) "clearance_edit" |
---|
[788] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[893] | 7 | ##parameters=REQUEST, acknowledge=None |
---|
[788] | 8 | ##title= |
---|
[805] | 9 | # $Id: clearance_edit.py 902 2006-11-20 07:39:43Z joachim $ |
---|
[788] | 10 | """ |
---|
| 11 | """ |
---|
| 12 | wftool = context.portal_workflow |
---|
| 13 | from urllib import urlencode |
---|
| 14 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
| 15 | import DateTime |
---|
| 16 | current = DateTime.DateTime() |
---|
| 17 | |
---|
[885] | 18 | cpsdocument_edit_button = REQUEST.has_key('cpsdocument_edit_button') |
---|
| 19 | cpsdocument_edit_and_view_button = REQUEST.has_key('cpsdocument_edit_and_view_button') |
---|
| 20 | clear_and_validate_button = REQUEST.has_key('clear_and_validate_button') |
---|
| 21 | reject_clearance_button = REQUEST.has_key('reject_clearance_button') |
---|
[893] | 22 | |
---|
[788] | 23 | # Until ajax posts directly to its own script... |
---|
| 24 | ##if 'ajax_edit' in REQUEST.form: |
---|
| 25 | ## return context.cpsdocument_edit_ajax(REQUEST, cluster=cluster) |
---|
| 26 | |
---|
| 27 | # Validate the document and write it if it's valid |
---|
| 28 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
[832] | 29 | wftool = context.portal_workflow |
---|
[788] | 30 | info = context.getStudentInfo() |
---|
| 31 | |
---|
| 32 | student = info['student'] |
---|
| 33 | app = info['app'] |
---|
| 34 | app_doc = info['app_doc'] |
---|
| 35 | clear = info['clear'] |
---|
| 36 | clear_doc = info['clear_doc'] |
---|
[832] | 37 | |
---|
[801] | 38 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
[788] | 39 | schema_id = 'student_clearance', |
---|
[885] | 40 | layout_id = 'student_clearance', |
---|
[788] | 41 | proxy=clear, |
---|
| 42 | use_session=True) |
---|
| 43 | |
---|
| 44 | psm = "" |
---|
| 45 | args = {} |
---|
[895] | 46 | action = "/external_clearance_edit_form" |
---|
[851] | 47 | if is_valid: |
---|
| 48 | if cpsdocument_edit_button: |
---|
[891] | 49 | psm = "Content changed!" |
---|
[851] | 50 | elif cpsdocument_edit_and_view_button: |
---|
[893] | 51 | if acknowledge: |
---|
| 52 | wftool.doActionFor(info['clear'],'close') |
---|
| 53 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
| 54 | psm = "You successfully requested clearance!" |
---|
[895] | 55 | if context.isStudent(): |
---|
| 56 | action = "/clearance_view" |
---|
[893] | 57 | else: |
---|
| 58 | psm = "You must tick the acknowledgement check box before submission!" |
---|
[895] | 59 | if context.isStudent(): |
---|
| 60 | action = "/clearance_edit_form" |
---|
[885] | 61 | elif clear_and_validate_button: |
---|
| 62 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
[891] | 63 | psm = "Clearance and eligibility record is validated and and student is cleared!" |
---|
[885] | 64 | elif reject_clearance_button: |
---|
| 65 | wftool.doActionFor(info['clear'],'open') |
---|
| 66 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
[891] | 67 | action = "/contact_student_form" |
---|
| 68 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
[851] | 69 | else: |
---|
[891] | 70 | psm = "Please correct your errors!" |
---|
| 71 | args = getFormUidUrlArg(REQUEST) |
---|
| 72 | |
---|
[851] | 73 | args['portal_status_message'] = psm |
---|
[891] | 74 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
[845] | 75 | REQUEST.RESPONSE.redirect(url) |
---|