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