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