[1860] | 1 | ## Script (Python) "clearance_edit" |
---|
[1107] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST, acknowledge=None |
---|
| 8 | ##title= |
---|
[805] | 9 | # $Id: clearance_edit.py 2363 2007-10-15 12:04:52Z 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() |
---|
[1016] | 17 | import logging |
---|
[1571] | 18 | logger = logging.getLogger('Skins.clearance_edit') |
---|
[1098] | 19 | request = REQUEST |
---|
[788] | 20 | |
---|
[885] | 21 | cpsdocument_edit_button = REQUEST.has_key('cpsdocument_edit_button') |
---|
| 22 | cpsdocument_edit_and_view_button = REQUEST.has_key('cpsdocument_edit_and_view_button') |
---|
| 23 | clear_and_validate_button = REQUEST.has_key('clear_and_validate_button') |
---|
| 24 | reject_clearance_button = REQUEST.has_key('reject_clearance_button') |
---|
[1098] | 25 | result_edit_button = REQUEST.has_key('result_edit_button') |
---|
[893] | 26 | |
---|
[788] | 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 | # Validate the document and write it if it's valid |
---|
| 32 | # (We don't call getEditableContent here, validate does it when needed.) |
---|
[832] | 33 | wftool = context.portal_workflow |
---|
[1073] | 34 | info = context.getClearanceInfo() |
---|
[788] | 35 | |
---|
[1036] | 36 | #'Sorry, you are not allowed to access this page!' |
---|
| 37 | if info == None: |
---|
[1073] | 38 | return REQUEST.RESPONSE.redirect(context.standard_error_message()) |
---|
[788] | 39 | student = info['student'] |
---|
[1098] | 40 | #app = info['app'] |
---|
| 41 | #app_doc = info['app_doc'] |
---|
[788] | 42 | clear = info['clear'] |
---|
| 43 | clear_doc = info['clear_doc'] |
---|
[1016] | 44 | student_id = info['id'] |
---|
| 45 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
[1098] | 46 | result_widgets = ('fst_sit_results', |
---|
| 47 | 'scd_sit_results', |
---|
| 48 | 'alr_results', |
---|
| 49 | ) |
---|
| 50 | required_scans = ('fst_sit_scan', |
---|
[2363] | 51 | 'age_dec', |
---|
| 52 | 'birth_certificate', |
---|
[1217] | 53 | # 'jamb_slip', |
---|
[1101] | 54 | 'ref_let', |
---|
[1098] | 55 | 'acc_let' |
---|
[1860] | 56 | ) |
---|
[1098] | 57 | form = request.form |
---|
| 58 | psm = "" |
---|
| 59 | args = {} |
---|
| 60 | action = "/external_clearance_edit_form" |
---|
[1860] | 61 | clearance_closed = False |
---|
| 62 | |
---|
[1098] | 63 | if context.isStudent(): |
---|
| 64 | action = "/clearance_edit_form" |
---|
[1860] | 65 | if info['clear_review_state'] == 'closed': |
---|
| 66 | clearance_closed = True |
---|
[832] | 67 | |
---|
[1860] | 68 | if not clearance_closed: |
---|
| 69 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
[788] | 70 | schema_id = 'student_clearance', |
---|
[885] | 71 | layout_id = 'student_clearance', |
---|
[788] | 72 | proxy=clear, |
---|
| 73 | use_session=True) |
---|
[1839] | 74 | if clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
| 75 | logger.info('%s cleared %s' % (member_id,student_id )) |
---|
| 76 | #from Products.zdb import set_trace |
---|
| 77 | #set_trace() |
---|
| 78 | info['clear_doc'].edit(mapping = {'cleared_date': current,}) |
---|
| 79 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
[2013] | 80 | psm = "Clearance and eligibility record is validated and student is cleared!" |
---|
[1839] | 81 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
| 82 | psm = "This student is already cleared!" |
---|
| 83 | elif reject_clearance_button: |
---|
| 84 | logger.info('%s rejected clearance for %s' % (member_id,student_id )) |
---|
| 85 | wftool.doActionFor(info['clear'],'open') |
---|
| 86 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
| 87 | action = "/external_contact_student_form" |
---|
| 88 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
| 89 | subject = "Clearance request rejected" |
---|
| 90 | args['subject'] = subject |
---|
| 91 | args['continue'] = 'external_clearance_edit_form' |
---|
[1860] | 92 | elif clearance_closed: |
---|
| 93 | action = "/clearance_view" |
---|
[1862] | 94 | logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id )) |
---|
[1839] | 95 | elif is_valid: |
---|
[1098] | 96 | if cpsdocument_edit_button or result_edit_button: |
---|
[891] | 97 | psm = "Content changed!" |
---|
[1996] | 98 | logger.info('%s edited clearance object of %s' % (member_id,student_id )) |
---|
| 99 | |
---|
[851] | 100 | elif cpsdocument_edit_and_view_button: |
---|
[1016] | 101 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
[1098] | 102 | missing = False |
---|
[2363] | 103 | #files = clear_doc.objectIds() |
---|
| 104 | # for scan in required_scans: |
---|
| 105 | # if scan not in files: |
---|
| 106 | # missing = True |
---|
| 107 | # break |
---|
| 108 | # if not missing: |
---|
| 109 | # if not "age_dec" in files and not "birth_certificate" in files: |
---|
| 110 | # missing = True |
---|
| 111 | if not context.waeup_tool.picturesExist(required_scans): |
---|
[1571] | 112 | logger.info('%s requested clearance with documents missing' % (student_id)) |
---|
[1106] | 113 | psm = "You have not uploaded all necessary documents to request clearance!" |
---|
[1098] | 114 | else: |
---|
[1571] | 115 | logger.info('%s requested clearance' % (student_id)) |
---|
[1098] | 116 | info['clear_doc'].edit(mapping = {'request_date': current,}) |
---|
| 117 | wftool.doActionFor(info['clear'],'close') |
---|
| 118 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
| 119 | psm = "You successfully requested clearance!" |
---|
| 120 | if context.isStudent(): |
---|
| 121 | action = "/clearance_view" |
---|
[1016] | 122 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
[1571] | 123 | logger.info('%s repeatedly requested clearance' % (student_id)) |
---|
[1017] | 124 | psm = "You have already requested clearance!" |
---|
[893] | 125 | else: |
---|
| 126 | psm = "You must tick the acknowledgement check box before submission!" |
---|
[851] | 127 | else: |
---|
[891] | 128 | psm = "Please correct your errors!" |
---|
| 129 | args = getFormUidUrlArg(REQUEST) |
---|
[1996] | 130 | logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id)) |
---|
[891] | 131 | |
---|
[851] | 132 | args['portal_status_message'] = psm |
---|
[891] | 133 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
[1575] | 134 | return REQUEST.RESPONSE.redirect(url) |
---|
[1106] | 135 | |
---|