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