[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 2119 2007-08-18 17:23:25Z 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 | |
---|
[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)) |
---|
| 65 | |
---|
[2098] | 66 | res,psm,ds = lt.renderLayout(layout_id= 'application', |
---|
| 67 | schema_id= 'application', |
---|
| 68 | layout_mode = mode, |
---|
| 69 | context=context, |
---|
| 70 | mapping=validate and REQUEST, |
---|
| 71 | ob=object, |
---|
| 72 | commit = False, |
---|
| 73 | ) |
---|
| 74 | |
---|
[2103] | 75 | if slip: |
---|
| 76 | return context.apply_pume_slip(rendered = res, |
---|
| 77 | psm = "", |
---|
| 78 | #psm = "%s, %s" % (psm,ds), |
---|
| 79 | mode = mode, |
---|
| 80 | ds = ds, |
---|
| 81 | ) |
---|
[2105] | 82 | |
---|
[2098] | 83 | if psm == 'invalid': |
---|
| 84 | return context.apply_pume_form(rendered = res, |
---|
| 85 | psm = "Please correct your input!", |
---|
| 86 | #psm = "%s, %s" % (psm,ds), |
---|
| 87 | mode = mode, |
---|
| 88 | ds = ds, |
---|
| 89 | ) |
---|
| 90 | elif psm == '': |
---|
| 91 | return context.apply_pume_form(rendered = res, |
---|
| 92 | psm = None, |
---|
| 93 | ds = ds, |
---|
| 94 | mode = mode, |
---|
| 95 | ) |
---|
| 96 | elif psm == 'valid': |
---|
| 97 | pass |
---|
[2102] | 98 | data = {} |
---|
[2114] | 99 | dm = ds.getDataModel() |
---|
| 100 | #set_trace() |
---|
[2102] | 101 | for field in context.applicants_catalog.schema(): |
---|
[2114] | 102 | if dm.has_key("%s" % field): |
---|
| 103 | data[field] = dm.get(field) |
---|
[2102] | 104 | data['reg_no'] = reg_no |
---|
| 105 | if apply_pume: |
---|
[2111] | 106 | if submitted: |
---|
| 107 | mode = "view" |
---|
| 108 | psm = "The form has already been submitted and you are not allowed to resubmit the data!" |
---|
[2119] | 109 | logger.info('%s tried to resubmit application record' % (reg_no)) |
---|
[2111] | 110 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 111 | schema_id= 'application', |
---|
| 112 | layout_mode = mode, |
---|
| 113 | context=context, |
---|
| 114 | mapping={}, |
---|
| 115 | ob=object, |
---|
| 116 | commit = False, |
---|
| 117 | ) |
---|
| 118 | elif not request.has_key('confirm'): |
---|
[2102] | 119 | mode = "edit" |
---|
[2111] | 120 | psm = "Please confirm Passport Photograph!" |
---|
[2119] | 121 | logger.info('%s tried to submit without ticking confirmation check box' % (reg_no)) |
---|
[2102] | 122 | else: |
---|
| 123 | mode = "view" |
---|
[2111] | 124 | psm = "You successfully applied for PUME!" |
---|
[2106] | 125 | data['application_date'] = current |
---|
| 126 | data['status'] = "submitted" |
---|
[2111] | 127 | context.applicants_catalog.modifyRecord(**data) |
---|
[2119] | 128 | logger.info('%s modified and submitted application record' % (reg_no)) |
---|
[2108] | 129 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application', |
---|
| 130 | schema_id= 'application', |
---|
| 131 | layout_mode = mode, |
---|
| 132 | context=context, |
---|
| 133 | mapping=validate and REQUEST, |
---|
| 134 | ob=object, |
---|
| 135 | commit = False, |
---|
[2111] | 136 | ) |
---|
[2102] | 137 | elif create: |
---|
| 138 | if submitted: |
---|
| 139 | mode = "view" |
---|
[2119] | 140 | logger.info('%s views application record' % (reg_no)) |
---|
[2102] | 141 | else: |
---|
| 142 | mode = "edit" |
---|
[2119] | 143 | logger.info('%s edits application process' % (reg_no)) |
---|
[2102] | 144 | psm = "" |
---|
| 145 | #set_trace() |
---|
| 146 | object['pin'] = str(ds.get('pin')) |
---|
[2111] | 147 | res,psm,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
[2102] | 148 | schema_id= 'application', |
---|
| 149 | layout_mode = mode, |
---|
| 150 | context=context, |
---|
| 151 | mapping={}, |
---|
| 152 | ob=object, |
---|
| 153 | commit = False, |
---|
| 154 | ) |
---|
| 155 | elif edit: |
---|
[2114] | 156 | #set_trace() |
---|
[2111] | 157 | if submitted: |
---|
| 158 | mode = "view" |
---|
| 159 | psm = "The form has already been submitted and you are not allowed to modify the data!" |
---|
[2119] | 160 | logger.info('%s tried to edit submitted application record' % (reg_no)) |
---|
[2111] | 161 | res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application', |
---|
| 162 | schema_id= 'application', |
---|
| 163 | layout_mode = mode, |
---|
| 164 | context=context, |
---|
| 165 | mapping={}, |
---|
| 166 | ob=object, |
---|
| 167 | commit = False, |
---|
| 168 | ) |
---|
| 169 | else: |
---|
| 170 | mode = "edit" |
---|
| 171 | psm = "Content changed" |
---|
| 172 | data['status'] = "edited" |
---|
| 173 | context.applicants_catalog.modifyRecord(**data) |
---|
[2119] | 174 | logger.info('%s modified application record' % (reg_no)) |
---|
[2098] | 175 | |
---|
[2108] | 176 | |
---|
[2111] | 177 | |
---|
[2102] | 178 | return context.apply_pume_form(rendered = res, |
---|
| 179 | psm = psm, |
---|
| 180 | #psm = "%s, %s" % (psm,ds), |
---|
| 181 | mode = mode, |
---|
| 182 | ds = ds, |
---|
| 183 | ) |
---|
[2098] | 184 | |
---|
[2102] | 185 | |
---|