[4199] | 1 | ## Script (Python) "apply_admission" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: apply_admission.py 4121 2009-05-10 09:15:06Z henrik $ |
---|
| 11 | """ |
---|
| 12 | process the Application Form |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | import DateTime |
---|
| 21 | import logging |
---|
| 22 | logger = logging.getLogger('Skins.apply_admission') |
---|
| 23 | |
---|
| 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | |
---|
| 27 | current = DateTime.DateTime() |
---|
| 28 | pr = context.portal_registration |
---|
| 29 | pprops = context.portal_properties |
---|
| 30 | request = REQUEST |
---|
| 31 | |
---|
| 32 | #manage = "manage" in request.keys() |
---|
[5234] | 33 | screening_types = ('prence','pce','cest','sandwich') |
---|
[4199] | 34 | if not (traverse_subpath and traverse_subpath[0] in screening_types): |
---|
| 35 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 36 | configuration = [] |
---|
| 37 | headings = {} |
---|
[5233] | 38 | headings['prence'] = 'Apply for Pre-NCE Programme (2010/2011)! ' |
---|
| 39 | headings['pce'] = 'Apply for PCE Screening Test (2010/2011)! ' |
---|
[6046] | 40 | headings['cest'] = 'Apply for Diploma Programme (2011/2012)! ' |
---|
| 41 | headings['sandwich'] = 'Apply for Sandwich Programme (2011/2012)! ' |
---|
[4199] | 42 | |
---|
| 43 | configuration += ('heading',headings), |
---|
| 44 | headings_slip = {} |
---|
[5233] | 45 | headings_slip['prence'] = 'Pre-NCE Application (2010/2011) Acknowledgement Slip' |
---|
| 46 | headings_slip['pce'] = 'PCE Screening (2010/2011) Acknowledgement Slip' |
---|
[6046] | 47 | headings_slip['cest'] = 'Application for Diploma Programme (2011/2012) Acknowledgement Slip' |
---|
| 48 | headings_slip['sandwich'] = 'Application for Sandwich Programme (2011/2012) Acknowledgement Slip' |
---|
[4199] | 49 | configuration += ('heading_slip',headings_slip), |
---|
| 50 | |
---|
| 51 | deaddates = {} |
---|
| 52 | |
---|
| 53 | #config_params = context.getConfigParams() |
---|
| 54 | |
---|
| 55 | deaddates['prence'] = DateTime.DateTime(pprops.date1) |
---|
[4542] | 56 | deaddates['pce'] = DateTime.DateTime(pprops.date5) |
---|
[4199] | 57 | deaddates['cest'] = DateTime.DateTime(pprops.date3) |
---|
| 58 | deaddates['sandwich'] = DateTime.DateTime(pprops.date4) |
---|
| 59 | configuration += ('deaddate',deaddates), |
---|
| 60 | |
---|
| 61 | deadline = {} |
---|
| 62 | for sct in screening_types: |
---|
| 63 | deadline[sct] = deaddates[sct].strftime('%A, %d. %B %Y') |
---|
| 64 | configuration += ('deadline',deadline), |
---|
| 65 | |
---|
| 66 | confirm = {} |
---|
| 67 | confirm['prence'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
| 68 | confirm['pce'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
| 69 | #confirm['cest'] = "I confirm that the Passport Photograph uploaded on this form is a true picture of me." |
---|
| 70 | confirm['cest'] = """I hereby acknowledge by ticking this check box that if it is discovered |
---|
| 71 | at any time, that I do not possess any of the qualifications, which I have obtained, I will be |
---|
[4693] | 72 | expelled from the College and shall not be readmitted for the same or any other programme, |
---|
[4199] | 73 | even if I have upgraded my previous qualification or posses additional qualifications.""" |
---|
| 74 | confirm['sandwich'] = """I hereby acknowledge by ticking this check box that if it is discovered |
---|
| 75 | at any time, that I do not possess any of the qualifications, which I have obtained, I will be |
---|
[4693] | 76 | expelled from the College and shall not be readmitted for the same or any other programme, |
---|
[4199] | 77 | even if I have upgraded my previous qualification or posses additional qualifications.""" |
---|
| 78 | configuration += ('confirm',confirm), |
---|
| 79 | |
---|
| 80 | #type_name = 'StudentApplication' |
---|
| 81 | #ti = context.portal_types[type_name] |
---|
| 82 | #REQUEST.set('type_name',type_name) |
---|
| 83 | create = "create" in request.keys() |
---|
| 84 | apply_admission = "apply" in request.keys() |
---|
| 85 | edit = "edit" in request.keys() or "cpsdocument_edit_button" in request.form.keys() |
---|
| 86 | slip = "slip" in request.keys() |
---|
| 87 | submitted = False |
---|
| 88 | mode = request.get('mode','') |
---|
| 89 | if not mode: |
---|
| 90 | if apply_admission or edit: |
---|
| 91 | mode = "edit" |
---|
| 92 | elif slip: |
---|
| 93 | mode = "view_slip" |
---|
| 94 | else: |
---|
| 95 | mode = "create" |
---|
| 96 | validate = create or edit or apply_admission |
---|
| 97 | |
---|
| 98 | without_reg_no = False |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | lt = context.portal_layouts |
---|
| 102 | object = {} |
---|
| 103 | pin = request.form.get('pin','') |
---|
| 104 | # reg_no = request.get('widget__reg_no','').upper() |
---|
| 105 | # if not reg_no: |
---|
| 106 | # reg_no = request.form.get('reg_no','').upper() |
---|
| 107 | info = {} |
---|
[5234] | 108 | screening_type = 'pce' |
---|
[4199] | 109 | if traverse_subpath and traverse_subpath[0] in screening_types: |
---|
| 110 | screening_type = traverse_subpath[0] |
---|
| 111 | without_reg_no = screening_type in ('prence','cest','sandwich') |
---|
| 112 | info['expired'] = current.greaterThan(deaddates[screening_type]) |
---|
| 113 | info['expiration_date'] = deaddates[screening_type] |
---|
| 114 | info['status'] = object.get('status','') |
---|
| 115 | info['screening_type'] = screening_type |
---|
| 116 | layout = "application_%s" % screening_type |
---|
| 117 | for co_name,co_dict in configuration: |
---|
| 118 | info[co_name] = co_dict[screening_type] |
---|
| 119 | # the reg_no is a hidden field in the form |
---|
| 120 | reg_no = request.form.get('reg_no','').upper() |
---|
| 121 | |
---|
| 122 | if not reg_no: |
---|
| 123 | # validate form if no reg_no specified |
---|
| 124 | res,psm,ds = lt.renderLayout(layout_id= layout, |
---|
| 125 | schema_id= 'import_application', |
---|
| 126 | layout_mode = mode, |
---|
| 127 | context=context, |
---|
| 128 | mapping=validate and REQUEST, |
---|
| 129 | ob={}, |
---|
| 130 | commit = False, |
---|
| 131 | ) |
---|
| 132 | if psm == 'invalid': |
---|
| 133 | return context.apply_admission_form(rendered = res, |
---|
| 134 | psm = "Please correct your input!", |
---|
| 135 | mode = mode, |
---|
| 136 | ds = ds, |
---|
| 137 | info = info, |
---|
| 138 | ) |
---|
| 139 | elif psm == '': |
---|
| 140 | return context.apply_admission_form(rendered = res, |
---|
| 141 | psm = psm, |
---|
| 142 | ds = ds, |
---|
| 143 | mode = mode, |
---|
| 144 | info = info, |
---|
| 145 | ) |
---|
| 146 | if without_reg_no: |
---|
| 147 | ## see fceokene #147 |
---|
[4201] | 148 | #reg_no = ds.get('pin_n','').upper() |
---|
| 149 | reg_no = ds.get('pin_p') + ds.get('pin_b') + ds.get('pin_n') |
---|
[4199] | 150 | else: |
---|
| 151 | reg_no = ds.get('reg_no') |
---|
| 152 | info['reg_no'] = reg_no |
---|
| 153 | |
---|
| 154 | brains = context.applicants_catalog(reg_no = reg_no.upper()) |
---|
| 155 | if len(brains) == 1: |
---|
| 156 | for field in context.applicants_catalog.schema(): |
---|
| 157 | object[field] = getattr(brains[0],field,None) |
---|
| 158 | screening_type = info['screening_type'] = object['screening_type'] |
---|
| 159 | for co_name,co_dict in configuration: |
---|
| 160 | info[co_name] = co_dict[screening_type] |
---|
| 161 | if not object['passport']: |
---|
| 162 | object['passport'] = '' |
---|
| 163 | if object['status'] and ('submitted' in object['status'] or 'admitted' in object['status'] or 'created' in object['status']): |
---|
| 164 | submitted = True |
---|
| 165 | # cannot happen anymore but anyway |
---|
| 166 | #if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
| 167 | # logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
| 168 | # return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 169 | |
---|
| 170 | #rerender with current object = application-record |
---|
| 171 | |
---|
| 172 | if slip: |
---|
| 173 | mode = "view_slip" |
---|
| 174 | logger.info('%s/%s views application slip' % (member,reg_no)) |
---|
| 175 | |
---|
| 176 | res,psm,ds = lt.renderLayout(layout_id= layout, |
---|
| 177 | schema_id= 'import_application', |
---|
| 178 | layout_mode = mode, |
---|
| 179 | context=context, |
---|
| 180 | mapping=validate and REQUEST, |
---|
| 181 | ob=object, |
---|
| 182 | commit = False, |
---|
| 183 | ) |
---|
| 184 | if slip: |
---|
| 185 | return context.apply_admission_slip(rendered = res, |
---|
| 186 | psm = "", |
---|
| 187 | mode = mode, |
---|
| 188 | ds = ds, |
---|
| 189 | info = info, |
---|
| 190 | ) |
---|
| 191 | |
---|
| 192 | if psm == 'invalid': |
---|
| 193 | return context.apply_admission_form(rendered = res, |
---|
| 194 | psm = "Please correct your input!", |
---|
| 195 | mode = mode, |
---|
| 196 | ds = ds, |
---|
| 197 | info = info, |
---|
| 198 | ) |
---|
| 199 | # For the next application session it should be reverted to |
---|
| 200 | # (see comment 09/06/07 16:40:52 in ticket #328): |
---|
| 201 | |
---|
| 202 | #if not create and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
| 203 | #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
| 204 | #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 205 | info['status'] = object.get('status','') |
---|
| 206 | |
---|
| 207 | data = {} |
---|
| 208 | dm = ds.getDataModel() |
---|
| 209 | for field in context.applicants_catalog.schema(): |
---|
| 210 | if dm.has_key("%s" % field): |
---|
| 211 | data[field] = dm.get(field) |
---|
| 212 | data['reg_no'] = reg_no |
---|
| 213 | |
---|
| 214 | if apply_admission: |
---|
| 215 | if submitted: |
---|
| 216 | mode = "view" |
---|
| 217 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
| 218 | logger.info('%s/%s tried to resubmit application record' % (member,reg_no)) |
---|
| 219 | # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
| 220 | # schema_id= 'import_application', |
---|
| 221 | # layout_mode = mode, |
---|
| 222 | # context=context, |
---|
| 223 | # mapping={}, |
---|
| 224 | # ob=object, |
---|
| 225 | # commit = False, |
---|
| 226 | # ) |
---|
| 227 | elif not request.has_key('confirm'): |
---|
| 228 | mode = "edit" |
---|
| 229 | psm = "Please confirm Passport Photograph!" |
---|
| 230 | logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no)) |
---|
| 231 | else: |
---|
| 232 | mode = "view" |
---|
| 233 | psm = "You successfully applied for admission!" |
---|
| 234 | if object['status'] == 'edited': |
---|
| 235 | data['status'] = "submitted" |
---|
| 236 | data['application_date'] = current |
---|
| 237 | logger.info('%s/%s modified and submitted application record' % (member,reg_no)) |
---|
| 238 | elif object['status'] == 'reset': |
---|
| 239 | data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y') |
---|
| 240 | logger.info('%s/%s modified and resubmitted application record' % (member,reg_no)) |
---|
| 241 | object['status'] = data['status'] |
---|
| 242 | context.applicants_catalog.modifyRecord(**data) |
---|
| 243 | # rerendering neccessary since object changed |
---|
| 244 | res,psm_dummy,ds = lt.renderLayout(layout_id= layout, |
---|
| 245 | schema_id= 'import_application', |
---|
| 246 | layout_mode = mode, |
---|
| 247 | context=context, |
---|
| 248 | mapping=validate and REQUEST, |
---|
| 249 | ob=object, |
---|
| 250 | commit = False, |
---|
| 251 | ) |
---|
| 252 | elif create: |
---|
| 253 | if submitted: |
---|
| 254 | mode = "view" |
---|
| 255 | logger.info('%s/%s views application record' % (member,reg_no)) |
---|
| 256 | else: |
---|
| 257 | mode = "edit" |
---|
| 258 | logger.info('%s/%s edits application record' % (member,reg_no)) |
---|
| 259 | psm = "" |
---|
| 260 | if without_reg_no: |
---|
| 261 | object['reg_no'] = reg_no |
---|
| 262 | object['pin'] = str(ds.get('pin')) |
---|
| 263 | # rerendering neccessary since object changed |
---|
| 264 | res,psm,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
| 265 | schema_id= 'import_application', |
---|
| 266 | layout_mode = mode, |
---|
| 267 | context=context, |
---|
| 268 | mapping={}, |
---|
| 269 | ob=object, |
---|
| 270 | commit = False, |
---|
| 271 | ) |
---|
| 272 | elif edit: |
---|
| 273 | if submitted: |
---|
| 274 | mode = "view" |
---|
| 275 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
| 276 | logger.info('%s/%s tried to edit submitted application record' % (member,reg_no)) |
---|
| 277 | # res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, |
---|
| 278 | # schema_id= 'import_application', |
---|
| 279 | # layout_mode = mode, |
---|
| 280 | # context=context, |
---|
| 281 | # mapping={}, |
---|
| 282 | # ob=object, |
---|
| 283 | # commit = False, |
---|
| 284 | # ) |
---|
| 285 | else: |
---|
| 286 | mode = "edit" |
---|
| 287 | psm = "Content changed!" |
---|
| 288 | data['status'] = "edited" |
---|
| 289 | #set_trace() |
---|
| 290 | context.applicants_catalog.modifyRecord(**data) |
---|
| 291 | logger.info('%s/%s modified application record' % (member,reg_no)) |
---|
| 292 | |
---|
| 293 | try: |
---|
| 294 | passport_uploaded = bool(data['passport']) |
---|
| 295 | except: |
---|
| 296 | passport_uploaded = False |
---|
| 297 | |
---|
| 298 | return context.apply_admission_form(rendered = res, |
---|
| 299 | psm = psm, |
---|
| 300 | mode = mode, |
---|
| 301 | show_submit = passport_uploaded, |
---|
| 302 | ds = ds, |
---|
| 303 | info = info, |
---|
| 304 | ) |
---|