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