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