[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 2146 2007-08-22 13:05:07Z joachim $ |
---|
| 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 | |
---|
[2098] | 24 | current = DateTime.DateTime() |
---|
| 25 | pr = context.portal_registration |
---|
| 26 | request = REQUEST |
---|
| 27 | |
---|
| 28 | #type_name = 'StudentApplication' |
---|
| 29 | #ti = context.portal_types[type_name] |
---|
| 30 | #REQUEST.set('type_name',type_name) |
---|
| 31 | create = "create" in request.keys() |
---|
| 32 | apply_pume = "apply" in request.keys() |
---|
| 33 | edit = "edit" in request.keys() |
---|
[2103] | 34 | slip = "slip" in request.keys() |
---|
[2102] | 35 | submitted = False |
---|
[2098] | 36 | mode = request.get('mode','') |
---|
| 37 | if not mode: |
---|
| 38 | if apply_pume or edit: |
---|
| 39 | mode = "edit" |
---|
| 40 | else: |
---|
| 41 | mode = "create" |
---|
| 42 | validate = create or edit or apply_pume |
---|
| 43 | |
---|
| 44 | lt = context.portal_layouts |
---|
| 45 | reg_no = request.get('widget__reg_no','').upper() |
---|
| 46 | if not reg_no: |
---|
[2102] | 47 | reg_no = request.form.get('reg_no','').upper() |
---|
| 48 | pin = request.form.get('pin','') |
---|
[2098] | 49 | object = {} |
---|
| 50 | if reg_no: |
---|
| 51 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
| 52 | if len(brains) == 1: |
---|
| 53 | for field in context.applicants_catalog.schema(): |
---|
| 54 | object[field] = getattr(brains[0],field,None) |
---|
[2114] | 55 | if not object['passport']: |
---|
| 56 | object['passport'] = '' |
---|
[2102] | 57 | if object['status'] == "submitted": |
---|
| 58 | submitted = True |
---|
| 59 | if not create and pin != object['pin']: |
---|
[2119] | 60 | logger.info('%s entered wrong pin %s' % (reg_no,pin)) |
---|
[2102] | 61 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[2103] | 62 | if slip: |
---|
| 63 | mode = "view_slip" |
---|
[2119] | 64 | logger.info('%s views application slip' % (reg_no)) |
---|
[2098] | 65 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
| 66 | schema_id= 'application', |
---|
| 67 | layout_mode = mode, |
---|
| 68 | context=context, |
---|
| 69 | mapping=validate and REQUEST, |
---|
| 70 | ob=object, |
---|
| 71 | commit = False, |
---|
| 72 | ) |
---|
| 73 | |
---|
[2103] | 74 | if slip: |
---|
| 75 | return context.apply_pume_slip(rendered = res, |
---|
| 76 | psm = "", |
---|
| 77 | #psm = "%s, %s" % (psm,ds), |
---|
| 78 | mode = mode, |
---|
| 79 | ds = ds, |
---|
| 80 | ) |
---|
[2105] | 81 | |
---|
[2098] | 82 | if psm == 'invalid': |
---|
| 83 | return context.apply_pume_form(rendered = res, |
---|
| 84 | psm = "Please correct your input!", |
---|
| 85 | #psm = "%s, %s" % (psm,ds), |
---|
| 86 | mode = mode, |
---|
| 87 | ds = ds, |
---|
| 88 | ) |
---|
| 89 | elif psm == '': |
---|
| 90 | return context.apply_pume_form(rendered = res, |
---|
| 91 | psm = None, |
---|
| 92 | ds = ds, |
---|
| 93 | mode = mode, |
---|
| 94 | ) |
---|
| 95 | elif psm == 'valid': |
---|
| 96 | pass |
---|
[2102] | 97 | data = {} |
---|
[2114] | 98 | dm = ds.getDataModel() |
---|
[2102] | 99 | for field in context.applicants_catalog.schema(): |
---|
[2114] | 100 | if dm.has_key("%s" % field): |
---|
| 101 | data[field] = dm.get(field) |
---|
[2102] | 102 | data['reg_no'] = reg_no |
---|
| 103 | if apply_pume: |
---|
[2111] | 104 | if submitted: |
---|
| 105 | mode = "view" |
---|
| 106 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
[2119] | 107 | logger.info('%s tried to resubmit application record' % (reg_no)) |
---|
[2111] | 108 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 109 | schema_id= 'application', |
---|
| 110 | layout_mode = mode, |
---|
| 111 | context=context, |
---|
| 112 | mapping={}, |
---|
| 113 | ob=object, |
---|
| 114 | commit = False, |
---|
| 115 | ) |
---|
[2136] | 116 | # elif not dm.get('passport'): |
---|
| 117 | # mode = "edit" |
---|
| 118 | # psm = "Please upload Passport Photograph!" |
---|
| 119 | # logger.info('%s tried to submit without uploading a passport foto' % (reg_no)) |
---|
[2111] | 120 | elif not request.has_key('confirm'): |
---|
[2102] | 121 | mode = "edit" |
---|
[2111] | 122 | psm = "Please confirm Passport Photograph!" |
---|
[2119] | 123 | logger.info('%s tried to submit without ticking confirmation check box' % (reg_no)) |
---|
[2102] | 124 | else: |
---|
| 125 | mode = "view" |
---|
[2111] | 126 | psm = "You successfully applied for PUME!" |
---|
[2106] | 127 | data['application_date'] = current |
---|
| 128 | data['status'] = "submitted" |
---|
[2111] | 129 | context.applicants_catalog.modifyRecord(**data) |
---|
[2119] | 130 | logger.info('%s modified and submitted application record' % (reg_no)) |
---|
[2108] | 131 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application', |
---|
| 132 | schema_id= 'application', |
---|
| 133 | layout_mode = mode, |
---|
| 134 | context=context, |
---|
| 135 | mapping=validate and REQUEST, |
---|
| 136 | ob=object, |
---|
| 137 | commit = False, |
---|
[2111] | 138 | ) |
---|
[2102] | 139 | elif create: |
---|
| 140 | if submitted: |
---|
| 141 | mode = "view" |
---|
[2119] | 142 | logger.info('%s views application record' % (reg_no)) |
---|
[2102] | 143 | else: |
---|
| 144 | mode = "edit" |
---|
[2141] | 145 | logger.info('%s edits application record' % (reg_no)) |
---|
[2102] | 146 | psm = "" |
---|
| 147 | #set_trace() |
---|
| 148 | object['pin'] = str(ds.get('pin')) |
---|
[2111] | 149 | res,psm,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
[2102] | 150 | schema_id= 'application', |
---|
| 151 | layout_mode = mode, |
---|
| 152 | context=context, |
---|
| 153 | mapping={}, |
---|
| 154 | ob=object, |
---|
| 155 | commit = False, |
---|
| 156 | ) |
---|
| 157 | elif edit: |
---|
[2111] | 158 | if submitted: |
---|
| 159 | mode = "view" |
---|
| 160 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
[2119] | 161 | logger.info('%s tried to edit submitted application record' % (reg_no)) |
---|
[2111] | 162 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 163 | schema_id= 'application', |
---|
| 164 | layout_mode = mode, |
---|
| 165 | context=context, |
---|
| 166 | mapping={}, |
---|
| 167 | ob=object, |
---|
| 168 | commit = False, |
---|
| 169 | ) |
---|
| 170 | else: |
---|
| 171 | mode = "edit" |
---|
| 172 | psm = "Content changed" |
---|
| 173 | data['status'] = "edited" |
---|
| 174 | context.applicants_catalog.modifyRecord(**data) |
---|
[2119] | 175 | logger.info('%s modified application record' % (reg_no)) |
---|
[2098] | 176 | |
---|
[2108] | 177 | |
---|
[2102] | 178 | return context.apply_pume_form(rendered = res, |
---|
| 179 | psm = psm, |
---|
| 180 | #psm = "%s, %s" % (psm,ds), |
---|
| 181 | mode = mode, |
---|
[2146] | 182 | show_submit = bool(data['passport']), |
---|
[2102] | 183 | ds = ds, |
---|
| 184 | ) |
---|
[2098] | 185 | |
---|
[2102] | 186 | |
---|