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