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