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