[2098] | 1 | ## Script (Python) "apply_pume" |
---|
| 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_pume.py 2161 2007-08-24 14:23:50Z henrik $ |
---|
| 11 | """ |
---|
| 12 | process the Pume Application Form |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | import DateTime |
---|
[2119] | 21 | import logging |
---|
| 22 | logger = logging.getLogger('Skins.apply_pume') |
---|
| 23 | |
---|
[2159] | 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | |
---|
[2098] | 27 | current = DateTime.DateTime() |
---|
| 28 | pr = context.portal_registration |
---|
| 29 | request = REQUEST |
---|
| 30 | |
---|
| 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_pume = "apply" in request.keys() |
---|
| 36 | edit = "edit" in request.keys() |
---|
[2103] | 37 | slip = "slip" in request.keys() |
---|
[2159] | 38 | manage = "manage" in request.keys() |
---|
[2102] | 39 | submitted = False |
---|
[2098] | 40 | mode = request.get('mode','') |
---|
| 41 | if not mode: |
---|
[2159] | 42 | if apply_pume or edit or manage: |
---|
[2098] | 43 | mode = "edit" |
---|
| 44 | else: |
---|
| 45 | mode = "create" |
---|
[2160] | 46 | validate = create or edit or apply_pume |
---|
[2098] | 47 | |
---|
[2160] | 48 | if manage: |
---|
| 49 | validate = False |
---|
| 50 | |
---|
[2098] | 51 | lt = context.portal_layouts |
---|
| 52 | reg_no = request.get('widget__reg_no','').upper() |
---|
| 53 | if not reg_no: |
---|
[2102] | 54 | reg_no = request.form.get('reg_no','').upper() |
---|
| 55 | pin = request.form.get('pin','') |
---|
[2098] | 56 | object = {} |
---|
| 57 | if reg_no: |
---|
| 58 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
| 59 | if len(brains) == 1: |
---|
| 60 | for field in context.applicants_catalog.schema(): |
---|
| 61 | object[field] = getattr(brains[0],field,None) |
---|
[2114] | 62 | if not object['passport']: |
---|
[2160] | 63 | object['passport'] = '' |
---|
[2161] | 64 | if 'submitted' in object['status']: |
---|
[2102] | 65 | submitted = True |
---|
[2159] | 66 | if not create and (pin != object['pin'] and not context.isSectionOfficer()): |
---|
| 67 | logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) |
---|
[2102] | 68 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[2103] | 69 | if slip: |
---|
| 70 | mode = "view_slip" |
---|
[2159] | 71 | logger.info('%s/%s views application slip' % (member,reg_no)) |
---|
[2160] | 72 | |
---|
[2098] | 73 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
| 74 | schema_id= 'application', |
---|
| 75 | layout_mode = mode, |
---|
| 76 | context=context, |
---|
| 77 | mapping=validate and REQUEST, |
---|
| 78 | ob=object, |
---|
| 79 | commit = False, |
---|
| 80 | ) |
---|
| 81 | |
---|
[2103] | 82 | if slip: |
---|
| 83 | return context.apply_pume_slip(rendered = res, |
---|
| 84 | psm = "", |
---|
| 85 | #psm = "%s, %s" % (psm,ds), |
---|
| 86 | mode = mode, |
---|
| 87 | ds = ds, |
---|
| 88 | ) |
---|
[2105] | 89 | |
---|
[2098] | 90 | if psm == 'invalid': |
---|
| 91 | return context.apply_pume_form(rendered = res, |
---|
| 92 | psm = "Please correct your input!", |
---|
| 93 | #psm = "%s, %s" % (psm,ds), |
---|
| 94 | mode = mode, |
---|
| 95 | ds = ds, |
---|
| 96 | ) |
---|
[2160] | 97 | elif psm == '' and not manage: |
---|
[2098] | 98 | return context.apply_pume_form(rendered = res, |
---|
| 99 | psm = None, |
---|
| 100 | ds = ds, |
---|
| 101 | mode = mode, |
---|
| 102 | ) |
---|
[2160] | 103 | elif psm == 'valid' or (psm == '' and manage): |
---|
[2098] | 104 | pass |
---|
[2102] | 105 | data = {} |
---|
[2114] | 106 | dm = ds.getDataModel() |
---|
[2102] | 107 | for field in context.applicants_catalog.schema(): |
---|
[2114] | 108 | if dm.has_key("%s" % field): |
---|
| 109 | data[field] = dm.get(field) |
---|
[2102] | 110 | data['reg_no'] = reg_no |
---|
[2160] | 111 | |
---|
| 112 | |
---|
| 113 | |
---|
[2102] | 114 | if apply_pume: |
---|
[2111] | 115 | if submitted: |
---|
| 116 | mode = "view" |
---|
| 117 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
[2159] | 118 | logger.info('%s/%s tried to resubmit application record' % (member,reg_no)) |
---|
[2111] | 119 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 120 | schema_id= 'application', |
---|
| 121 | layout_mode = mode, |
---|
| 122 | context=context, |
---|
| 123 | mapping={}, |
---|
| 124 | ob=object, |
---|
| 125 | commit = False, |
---|
| 126 | ) |
---|
| 127 | elif not request.has_key('confirm'): |
---|
[2102] | 128 | mode = "edit" |
---|
[2111] | 129 | psm = "Please confirm Passport Photograph!" |
---|
[2159] | 130 | logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no)) |
---|
[2102] | 131 | else: |
---|
| 132 | mode = "view" |
---|
[2111] | 133 | psm = "You successfully applied for PUME!" |
---|
[2106] | 134 | data['application_date'] = current |
---|
[2161] | 135 | if object['status'] == 'edited': |
---|
| 136 | data['status'] = "submitted" |
---|
| 137 | logger.info('%s/%s modified and submitted application record' % (member,reg_no)) |
---|
| 138 | elif object['status'] == 'reset': |
---|
| 139 | data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y') |
---|
| 140 | logger.info('%s/%s modified and resubmitted application record' % (member,reg_no)) |
---|
| 141 | object['status'] = data['status'] |
---|
[2111] | 142 | context.applicants_catalog.modifyRecord(**data) |
---|
[2161] | 143 | |
---|
[2108] | 144 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application', |
---|
| 145 | schema_id= 'application', |
---|
| 146 | layout_mode = mode, |
---|
| 147 | context=context, |
---|
| 148 | mapping=validate and REQUEST, |
---|
| 149 | ob=object, |
---|
| 150 | commit = False, |
---|
[2111] | 151 | ) |
---|
[2102] | 152 | elif create: |
---|
| 153 | if submitted: |
---|
| 154 | mode = "view" |
---|
[2159] | 155 | logger.info('%s/%s views application record' % (member,reg_no)) |
---|
[2102] | 156 | else: |
---|
| 157 | mode = "edit" |
---|
[2159] | 158 | logger.info('%s/%s edits application record' % (member,reg_no)) |
---|
[2102] | 159 | psm = "" |
---|
| 160 | #set_trace() |
---|
| 161 | object['pin'] = str(ds.get('pin')) |
---|
[2111] | 162 | res,psm,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
[2102] | 163 | schema_id= 'application', |
---|
| 164 | layout_mode = mode, |
---|
| 165 | context=context, |
---|
| 166 | mapping={}, |
---|
| 167 | ob=object, |
---|
| 168 | commit = False, |
---|
| 169 | ) |
---|
| 170 | elif edit: |
---|
[2111] | 171 | if submitted: |
---|
| 172 | mode = "view" |
---|
| 173 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
[2159] | 174 | logger.info('%s/%s tried to edit submitted application record' % (member,reg_no)) |
---|
[2111] | 175 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 176 | schema_id= 'application', |
---|
| 177 | layout_mode = mode, |
---|
| 178 | context=context, |
---|
| 179 | mapping={}, |
---|
| 180 | ob=object, |
---|
| 181 | commit = False, |
---|
| 182 | ) |
---|
| 183 | else: |
---|
| 184 | mode = "edit" |
---|
| 185 | psm = "Content changed" |
---|
| 186 | data['status'] = "edited" |
---|
| 187 | context.applicants_catalog.modifyRecord(**data) |
---|
[2159] | 188 | logger.info('%s/%s modified application record' % (member,reg_no)) |
---|
[2098] | 189 | |
---|
[2161] | 190 | elif manage: |
---|
[2159] | 191 | if submitted: |
---|
| 192 | mode = "view" |
---|
| 193 | psm = "You are now assuming the applicant's role!" |
---|
| 194 | logger.info('%s/%s entered application record' % (member,reg_no)) |
---|
| 195 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 196 | schema_id= 'application', |
---|
| 197 | layout_mode = mode, |
---|
| 198 | context=context, |
---|
| 199 | mapping={}, |
---|
| 200 | ob=object, |
---|
| 201 | commit = False, |
---|
| 202 | ) |
---|
| 203 | else: |
---|
| 204 | mode = "edit" |
---|
| 205 | psm = "You are now assuming the applicant's role!" |
---|
| 206 | logger.info('%s/%s entered application record' % (member,reg_no)) |
---|
[2108] | 207 | |
---|
[2159] | 208 | |
---|
[2161] | 209 | try: |
---|
[2160] | 210 | passport_uploaded = bool(data['passport']) |
---|
| 211 | except: |
---|
| 212 | passport_uploaded = False |
---|
| 213 | |
---|
[2102] | 214 | return context.apply_pume_form(rendered = res, |
---|
| 215 | psm = psm, |
---|
| 216 | #psm = "%s, %s" % (psm,ds), |
---|
| 217 | mode = mode, |
---|
[2160] | 218 | show_submit = passport_uploaded, |
---|
[2102] | 219 | ds = ds, |
---|
| 220 | ) |
---|
[2098] | 221 | |
---|
[2102] | 222 | |
---|