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