[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 2676 2007-11-16 11:17:54Z henrik $ |
---|
[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: |
---|
[2364] | 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', |
---|
[1217] | 51 | # 'jamb_slip', |
---|
[1101] | 52 | 'ref_let', |
---|
[1098] | 53 | 'acc_let' |
---|
[1860] | 54 | ) |
---|
[1098] | 55 | form = request.form |
---|
| 56 | psm = "" |
---|
| 57 | args = {} |
---|
| 58 | action = "/external_clearance_edit_form" |
---|
[1860] | 59 | clearance_closed = False |
---|
| 60 | |
---|
[1098] | 61 | if context.isStudent(): |
---|
| 62 | action = "/clearance_edit_form" |
---|
[1860] | 63 | if info['clear_review_state'] == 'closed': |
---|
| 64 | clearance_closed = True |
---|
[832] | 65 | |
---|
[1860] | 66 | if not clearance_closed: |
---|
| 67 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
[788] | 68 | schema_id = 'student_clearance', |
---|
[885] | 69 | layout_id = 'student_clearance', |
---|
[788] | 70 | proxy=clear, |
---|
[2373] | 71 | use_session=False) |
---|
[1839] | 72 | if clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
| 73 | logger.info('%s cleared %s' % (member_id,student_id )) |
---|
| 74 | #from Products.zdb import set_trace |
---|
| 75 | #set_trace() |
---|
[2670] | 76 | clear_doc.edit(mapping = {'cleared_date': current,}) |
---|
[1839] | 77 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
[2672] | 78 | |
---|
| 79 | |
---|
| 80 | if clear_doc.firstname and clear_doc.lastname: |
---|
| 81 | if info['per_review_state'] != 'opened': |
---|
| 82 | wftool.doActionFor(info['per'],'open') |
---|
| 83 | per_doc = info['per'].getContent() |
---|
[2676] | 84 | firstname = clear_doc.firstname.replace('-',' - ') |
---|
| 85 | firstname = ' '.join([m.capitalize() for m in firstname.split()]) |
---|
| 86 | firstname = firstname.replace(' - ','-') |
---|
| 87 | middlename = clear_doc.middlename.replace('-',' - ') |
---|
| 88 | middlename = ' '.join([m.capitalize() for m in middlename.split()]) |
---|
| 89 | middlename = middlename.replace(' - ','-') |
---|
| 90 | lastname = clear_doc.lastname.replace('-',' - ') |
---|
| 91 | lastname = ' '.join([m.capitalize() for m in lastname.split()]) |
---|
| 92 | lastname = lastname.replace(' - ','-') |
---|
| 93 | per_doc.edit(mapping = {'firstname': firstname, 'middlename': middlename, 'lastname': lastname,}) |
---|
[2672] | 94 | |
---|
[2013] | 95 | psm = "Clearance and eligibility record is validated and student is cleared!" |
---|
[1839] | 96 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
| 97 | psm = "This student is already cleared!" |
---|
| 98 | elif reject_clearance_button: |
---|
| 99 | logger.info('%s rejected clearance for %s' % (member_id,student_id )) |
---|
[2491] | 100 | try: |
---|
| 101 | wftool.doActionFor(info['clear'],'open') |
---|
| 102 | except: |
---|
| 103 | return |
---|
[1839] | 104 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
| 105 | action = "/external_contact_student_form" |
---|
| 106 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
| 107 | subject = "Clearance request rejected" |
---|
| 108 | args['subject'] = subject |
---|
| 109 | args['continue'] = 'external_clearance_edit_form' |
---|
[1860] | 110 | elif clearance_closed: |
---|
| 111 | action = "/clearance_view" |
---|
[1862] | 112 | logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id )) |
---|
[1839] | 113 | elif is_valid: |
---|
[1098] | 114 | if cpsdocument_edit_button or result_edit_button: |
---|
[891] | 115 | psm = "Content changed!" |
---|
[1996] | 116 | logger.info('%s edited clearance object of %s' % (member_id,student_id )) |
---|
[851] | 117 | elif cpsdocument_edit_and_view_button: |
---|
[1016] | 118 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
[2364] | 119 | files = context.waeup_tool.picturesList() |
---|
| 120 | req_found = [scan for scan in required_scans if scan in files] |
---|
| 121 | birth_found = "age_dec" in files or "birth_certificate" in files |
---|
[2673] | 122 | if not req_found or not birth_found: |
---|
| 123 | logger.info('%s requested clearance with documents missing' % (student_id)) |
---|
| 124 | psm = "You have not uploaded all necessary documents to request clearance!" |
---|
| 125 | elif not clear_doc.firstname or not clear_doc.lastname: |
---|
[2670] | 126 | logger.info('%s requested clearance without confirming name' % (student_id)) |
---|
[2672] | 127 | psm = "Please fill the name fields! First and last name are required. " |
---|
[1098] | 128 | else: |
---|
[1571] | 129 | logger.info('%s requested clearance' % (student_id)) |
---|
[2670] | 130 | clear_doc.edit(mapping = {'request_date': current,}) |
---|
[1098] | 131 | wftool.doActionFor(info['clear'],'close') |
---|
| 132 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
| 133 | psm = "You successfully requested clearance!" |
---|
| 134 | if context.isStudent(): |
---|
| 135 | action = "/clearance_view" |
---|
[1016] | 136 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
[1571] | 137 | logger.info('%s repeatedly requested clearance' % (student_id)) |
---|
[1017] | 138 | psm = "You have already requested clearance!" |
---|
[893] | 139 | else: |
---|
| 140 | psm = "You must tick the acknowledgement check box before submission!" |
---|
[851] | 141 | else: |
---|
[891] | 142 | psm = "Please correct your errors!" |
---|
| 143 | args = getFormUidUrlArg(REQUEST) |
---|
[1996] | 144 | logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id)) |
---|
[891] | 145 | |
---|
[851] | 146 | args['portal_status_message'] = psm |
---|
[891] | 147 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
[1575] | 148 | return REQUEST.RESPONSE.redirect(url) |
---|
[1106] | 149 | |
---|