[3968] | 1 | ## Script (Python) "clearance_edit" |
---|
| 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= |
---|
| 9 | # $Id: clearance_edit.py 3814 2008-12-12 15:23:38Z henrik $ |
---|
| 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 | import logging |
---|
| 18 | logger = logging.getLogger('Skins.clearance_edit') |
---|
| 19 | request = REQUEST |
---|
| 20 | |
---|
| 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') |
---|
| 25 | result_edit_button = REQUEST.has_key('result_edit_button') |
---|
| 26 | |
---|
| 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.) |
---|
| 33 | wftool = context.portal_workflow |
---|
| 34 | info = context.getClearanceInfo() |
---|
| 35 | |
---|
| 36 | #'Sorry, you are not allowed to access this page!' |
---|
| 37 | if info == None: |
---|
| 38 | return REQUEST.RESPONSE.redirect(context.standard_error_message()) |
---|
| 39 | student = info['student'] |
---|
| 40 | #app = info['app'] |
---|
| 41 | #app_doc = info['app_doc'] |
---|
| 42 | clear = info['clear'] |
---|
| 43 | clear_doc = info['clear_doc'] |
---|
| 44 | student_id = info['id'] |
---|
| 45 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
| 46 | result_widgets = ('fst_sit_results', |
---|
| 47 | 'scd_sit_results', |
---|
| 48 | 'alr_results', |
---|
| 49 | ) |
---|
| 50 | required_scans = ('fst_sit_scan', |
---|
| 51 | # 'jamb_slip', |
---|
| 52 | 'lga_ident', |
---|
| 53 | 'stat_dec', |
---|
| 54 | 'ref_let', |
---|
| 55 | 'acc_let', |
---|
| 56 | 'signature' |
---|
| 57 | ) |
---|
| 58 | # start customization |
---|
| 59 | |
---|
| 60 | no_scans_required = False |
---|
| 61 | |
---|
| 62 | # end customization |
---|
| 63 | |
---|
| 64 | form = request.form |
---|
| 65 | psm = "" |
---|
| 66 | args = {} |
---|
| 67 | action = "/external_clearance_edit_form" |
---|
| 68 | clearance_closed = False |
---|
| 69 | |
---|
| 70 | if context.isStudent(): |
---|
| 71 | action = "/clearance_edit_form" |
---|
| 72 | if info['clear_review_state'] == 'closed': |
---|
| 73 | clearance_closed = True |
---|
| 74 | |
---|
| 75 | if not clearance_closed: |
---|
| 76 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
| 77 | schema_id = 'student_clearance', |
---|
| 78 | layout_id = 'student_clearance', |
---|
| 79 | proxy=clear, |
---|
| 80 | use_session=False) |
---|
| 81 | if clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
| 82 | logger.info('%s cleared %s' % (member_id,student_id )) |
---|
| 83 | #from Products.zdb import set_trace |
---|
| 84 | #set_trace() |
---|
| 85 | clear_doc.edit(mapping = {'clearance_officer': member_id, |
---|
| 86 | 'cleared_date': current,}) |
---|
| 87 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
| 88 | if clear_doc.firstname and clear_doc.lastname: |
---|
| 89 | if info['per_review_state'] != 'opened': |
---|
| 90 | wftool.doActionFor(info['per'],'open') |
---|
| 91 | per_doc = info['per'].getContent() |
---|
| 92 | firstname = clear_doc.firstname.replace('-',' - ') |
---|
| 93 | firstname = ' '.join([m.capitalize() for m in firstname.split()]) |
---|
| 94 | firstname = firstname.replace(' - ','-') |
---|
| 95 | middlename = clear_doc.middlename.replace('-',' - ') |
---|
| 96 | middlename = ' '.join([m.capitalize() for m in middlename.split()]) |
---|
| 97 | middlename = middlename.replace(' - ','-') |
---|
| 98 | lastname = clear_doc.lastname.replace('-',' - ') |
---|
| 99 | lastname = ' '.join([m.capitalize() for m in lastname.split()]) |
---|
| 100 | lastname = lastname.replace(' - ','-') |
---|
| 101 | # we changed |
---|
| 102 | context.waeup_tool.updateRoleMappingsFor('waeup_student_subobject_wf',info['per']) |
---|
| 103 | per_doc.edit(mapping = {'firstname': firstname, 'middlename': middlename, 'lastname': lastname,}) |
---|
| 104 | |
---|
| 105 | psm = "Clearance and eligibility record is validated and student is cleared!" |
---|
| 106 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
| 107 | psm = "This student is already cleared!" |
---|
| 108 | elif reject_clearance_button: |
---|
| 109 | logger.info('%s rejected clearance for %s' % (member_id,student_id )) |
---|
| 110 | try: |
---|
| 111 | wftool.doActionFor(info['clear'],'open') |
---|
| 112 | except: |
---|
| 113 | return |
---|
| 114 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
| 115 | action = "/external_contact_student_form" |
---|
| 116 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
| 117 | subject = "Clearance request rejected" |
---|
| 118 | args['subject'] = subject |
---|
| 119 | args['continue'] = 'external_clearance_edit_form' |
---|
| 120 | elif clearance_closed: |
---|
| 121 | action = "/clearance_view" |
---|
| 122 | logger.info('%s tried to edit closed clearance object of %s' % (member_id,student_id )) |
---|
| 123 | elif is_valid: |
---|
| 124 | if cpsdocument_edit_button or result_edit_button: |
---|
| 125 | psm = "Content changed!" |
---|
| 126 | logger.info('%s edited clearance object of %s' % (member_id,student_id )) |
---|
| 127 | elif cpsdocument_edit_and_view_button: |
---|
| 128 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
| 129 | files = context.waeup_tool.picturesList() |
---|
| 130 | req_found = [scan for scan in required_scans if scan in files] or no_scans_required |
---|
| 131 | birth_found = "age_dec" in files or "birth_certificate" in files or no_scans_required |
---|
| 132 | if not req_found or not birth_found: |
---|
| 133 | logger.info('%s requested clearance with documents missing' % (student_id)) |
---|
| 134 | psm = "You have not uploaded all necessary documents to request clearance!" |
---|
| 135 | elif not clear_doc.firstname or not clear_doc.lastname: |
---|
| 136 | logger.info('%s requested clearance without confirming name' % (student_id)) |
---|
| 137 | psm = "Please fill the name fields! First and last name are required. " |
---|
| 138 | else: |
---|
| 139 | logger.info('%s requested clearance' % (student_id)) |
---|
| 140 | clear_doc.edit(mapping = {'request_date': current,}) |
---|
| 141 | wftool.doActionFor(info['clear'],'close') |
---|
| 142 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
| 143 | psm = "You successfully requested clearance!" |
---|
| 144 | if context.isStudent(): |
---|
| 145 | action = "/clearance_view" |
---|
| 146 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
| 147 | logger.info('%s repeatedly requested clearance' % (student_id)) |
---|
| 148 | psm = "You have already requested clearance!" |
---|
| 149 | else: |
---|
| 150 | psm = "You must tick the acknowledgement check box before submission!" |
---|
| 151 | else: |
---|
| 152 | psm = "Please correct your errors!" |
---|
| 153 | args = getFormUidUrlArg(REQUEST) |
---|
| 154 | logger.info('%s got error when editing the clearance object of %s' % (member_id,student_id)) |
---|
| 155 | |
---|
| 156 | args['portal_status_message'] = psm |
---|
| 157 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
| 158 | return REQUEST.RESPONSE.redirect(url) |
---|
| 159 | |
---|