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