[1853] | 1 | z## 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 1853 2007-06-04 10:23:30Z 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: |
---|
[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', |
---|
[1217] | 51 | # 'jamb_slip', |
---|
[1101] | 52 | 'ref_let', |
---|
[1098] | 53 | 'acc_let' |
---|
| 54 | ) |
---|
| 55 | form = request.form |
---|
| 56 | psm = "" |
---|
| 57 | args = {} |
---|
| 58 | action = "/external_clearance_edit_form" |
---|
| 59 | if context.isStudent(): |
---|
| 60 | action = "/clearance_edit_form" |
---|
[832] | 61 | |
---|
[801] | 62 | is_valid, ds = clear_doc.validate(request=REQUEST, |
---|
[788] | 63 | schema_id = 'student_clearance', |
---|
[885] | 64 | layout_id = 'student_clearance', |
---|
[788] | 65 | proxy=clear, |
---|
| 66 | use_session=True) |
---|
| 67 | |
---|
[1839] | 68 | if clear_and_validate_button and info['review_state'] == "clearance_requested": |
---|
| 69 | logger.info('%s cleared %s' % (member_id,student_id )) |
---|
| 70 | #from Products.zdb import set_trace |
---|
| 71 | #set_trace() |
---|
| 72 | info['clear_doc'].edit(mapping = {'cleared_date': current,}) |
---|
| 73 | wftool.doActionFor(info['student'],'clear_and_validate') |
---|
| 74 | psm = "Clearance and eligibility record is validated and and student is cleared!" |
---|
| 75 | elif clear_and_validate_button and info['review_state'] == "cleared_and_validated": |
---|
| 76 | psm = "This student is already cleared!" |
---|
| 77 | elif reject_clearance_button: |
---|
| 78 | logger.info('%s rejected clearance for %s' % (member_id,student_id )) |
---|
| 79 | wftool.doActionFor(info['clear'],'open') |
---|
| 80 | wftool.doActionFor(info['student'],'reject_clearance') |
---|
| 81 | action = "/external_contact_student_form" |
---|
| 82 | psm = "Student's clearance request has been rejected! Please fill and submit the form below!" |
---|
| 83 | subject = "Clearance request rejected" |
---|
| 84 | args['subject'] = subject |
---|
| 85 | args['continue'] = 'external_clearance_edit_form' |
---|
| 86 | elif is_valid: |
---|
[1098] | 87 | if cpsdocument_edit_button or result_edit_button: |
---|
[891] | 88 | psm = "Content changed!" |
---|
[1571] | 89 | logger.info('%s edited clearance of %s' % (member_id,student_id )) |
---|
[1027] | 90 | if clear_doc.clr_ac_pin == "": |
---|
| 91 | res = context.portal_pins(student=member_id) |
---|
| 92 | if res: |
---|
| 93 | p = res[0].pin |
---|
| 94 | if len(p) > 10: |
---|
| 95 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
| 96 | else: |
---|
| 97 | pin = p |
---|
| 98 | clear_doc.edit(mapping={'clr_ac_pin': pin}) |
---|
[851] | 99 | elif cpsdocument_edit_and_view_button: |
---|
[1016] | 100 | if acknowledge and info['review_state'] == "clearance_pin_entered": |
---|
[1098] | 101 | missing = False |
---|
[1110] | 102 | files = clear_doc.objectIds() |
---|
[1098] | 103 | for scan in required_scans: |
---|
[1110] | 104 | if scan not in files: |
---|
[1098] | 105 | missing = True |
---|
| 106 | break |
---|
| 107 | if not missing: |
---|
[1110] | 108 | if not "age_dec" in files and not "birth_certificate" in files: |
---|
[1098] | 109 | missing = True |
---|
| 110 | if missing: |
---|
[1571] | 111 | logger.info('%s requested clearance with documents missing' % (student_id)) |
---|
[1106] | 112 | psm = "You have not uploaded all necessary documents to request clearance!" |
---|
[1098] | 113 | else: |
---|
[1571] | 114 | logger.info('%s requested clearance' % (student_id)) |
---|
[1098] | 115 | info['clear_doc'].edit(mapping = {'request_date': current,}) |
---|
| 116 | wftool.doActionFor(info['clear'],'close') |
---|
| 117 | wftool.doActionFor(info['student'],'request_clearance',dest_container=1) |
---|
| 118 | psm = "You successfully requested clearance!" |
---|
| 119 | if context.isStudent(): |
---|
| 120 | action = "/clearance_view" |
---|
[1016] | 121 | elif acknowledge and info['review_state'] != "clearance_pin_entered": |
---|
[1571] | 122 | logger.info('%s repeatedly requested clearance' % (student_id)) |
---|
[1017] | 123 | psm = "You have already requested clearance!" |
---|
[893] | 124 | else: |
---|
| 125 | psm = "You must tick the acknowledgement check box before submission!" |
---|
[851] | 126 | else: |
---|
[891] | 127 | psm = "Please correct your errors!" |
---|
| 128 | args = getFormUidUrlArg(REQUEST) |
---|
[1837] | 129 | logger.info('%s got error when editing %s' % (member_id,student_id)) |
---|
[891] | 130 | |
---|
[851] | 131 | args['portal_status_message'] = psm |
---|
[891] | 132 | url = clear.absolute_url() + action + '?' + urlencode(args) |
---|
[1575] | 133 | return REQUEST.RESPONSE.redirect(url) |
---|
[1106] | 134 | |
---|