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