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