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