[2160] | 1 | ## Script (Python) "apply_pume_manage" |
---|
[2156] | 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_manage.py 2168 2007-08-29 06:24:39Z henrik $ |
---|
| 11 | """ |
---|
| 12 | search for Pume Applications |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | try: |
---|
| 16 | from Products.zdb import set_trace |
---|
| 17 | except: |
---|
| 18 | def set_trace(): |
---|
| 19 | pass |
---|
| 20 | |
---|
| 21 | import DateTime |
---|
| 22 | import logging |
---|
| 23 | logger = logging.getLogger('Skins.apply_pume_manage') |
---|
| 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | |
---|
| 27 | current = DateTime.DateTime() |
---|
| 28 | pr = context.portal_registration |
---|
| 29 | request = REQUEST |
---|
| 30 | |
---|
| 31 | |
---|
[2158] | 32 | if not context.isSectionOfficer(): |
---|
[2156] | 33 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.absolete_url()) |
---|
[2158] | 34 | |
---|
[2156] | 35 | #type_name = 'StudentApplication' |
---|
| 36 | #ti = context.portal_types[type_name] |
---|
| 37 | #REQUEST.set('type_name',type_name) |
---|
| 38 | reset = "reset" in request.keys() |
---|
[2168] | 39 | edit = "edit" in request.keys() |
---|
[2156] | 40 | lt = context.portal_layouts |
---|
[2157] | 41 | |
---|
[2160] | 42 | reg_no = request.get('reg_no','').upper() |
---|
| 43 | new_reg_no = request.get('new_reg_no','').upper() |
---|
[2157] | 44 | |
---|
[2168] | 45 | if reset or edit: |
---|
[2157] | 46 | reg_no = reg_no |
---|
| 47 | elif new_reg_no: |
---|
| 48 | reg_no = new_reg_no |
---|
| 49 | |
---|
[2156] | 50 | res = '' |
---|
| 51 | psm = '' |
---|
| 52 | object = {} |
---|
[2168] | 53 | ds = [] |
---|
| 54 | |
---|
| 55 | if reg_no: |
---|
| 56 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
| 57 | if len(brains) == 1: |
---|
| 58 | for field in context.applicants_catalog.schema(): |
---|
| 59 | object[field] = getattr(brains[0],field,None) |
---|
| 60 | |
---|
| 61 | res,psm,ds = lt.renderLayout(layout_id= 'application_manage', |
---|
| 62 | schema_id= 'application', |
---|
| 63 | layout_mode = "edit", |
---|
| 64 | context=context, |
---|
| 65 | mapping=REQUEST, |
---|
| 66 | ob=object, |
---|
| 67 | commit = False, |
---|
| 68 | ) |
---|
| 69 | if psm == 'invalid': |
---|
| 70 | return context.apply_pume_manage_form(rendered = res, |
---|
| 71 | psm = "Please correct your input!", |
---|
| 72 | #psm = "%s, %s" % (psm,ds), |
---|
| 73 | ds = ds, |
---|
| 74 | ) |
---|
| 75 | elif psm == '': |
---|
| 76 | psm = 'Registration Number not found!' |
---|
| 77 | return context.apply_pume_manage_form(rendered = res, |
---|
| 78 | psm = psm, |
---|
| 79 | ds = ds, |
---|
| 80 | ) |
---|
| 81 | elif psm == 'valid': |
---|
| 82 | psm = '' |
---|
| 83 | pass |
---|
| 84 | |
---|
[2156] | 85 | data = {} |
---|
[2168] | 86 | dm = ds.getDataModel() |
---|
| 87 | for field in context.applicants_catalog.schema(): |
---|
| 88 | if dm.has_key("%s" % field): |
---|
| 89 | data[field] = dm.get(field) |
---|
| 90 | |
---|
| 91 | |
---|
[2156] | 92 | if reset and reg_no: |
---|
[2168] | 93 | #data['reg_no'] = reg_no |
---|
[2157] | 94 | psm = "You successfully reset the record! The applicant will be able to edit and resubmit the data." |
---|
[2161] | 95 | data['status'] = "reset" |
---|
[2156] | 96 | context.applicants_catalog.modifyRecord(**data) |
---|
| 97 | logger.info('%s reset application record of %s' % (member,reg_no)) |
---|
[2157] | 98 | |
---|
[2168] | 99 | if edit and reg_no: |
---|
| 100 | #data['reg_no'] = reg_no |
---|
| 101 | psm = "Content changed!" |
---|
| 102 | context.applicants_catalog.modifyRecord(**data) |
---|
| 103 | logger.info('%s edited application record of %s' % (member,reg_no)) |
---|
| 104 | |
---|
[2158] | 105 | #set_trace() |
---|
| 106 | |
---|
[2168] | 107 | |
---|
[2156] | 108 | if reg_no: |
---|
| 109 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
| 110 | if len(brains) == 1: |
---|
| 111 | for field in context.applicants_catalog.schema(): |
---|
| 112 | object[field] = getattr(brains[0],field,None) |
---|
[2168] | 113 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application_manage', |
---|
[2156] | 114 | schema_id= 'application', |
---|
[2168] | 115 | layout_mode = "edit", |
---|
[2156] | 116 | context=context, |
---|
| 117 | ob=object, |
---|
| 118 | commit = False, |
---|
| 119 | ) |
---|
| 120 | else: |
---|
| 121 | psm = "reg no %s not found" % reg_no |
---|
[2158] | 122 | |
---|
[2156] | 123 | return context.apply_pume_manage_form(rendered = res, |
---|
| 124 | psm = psm, |
---|
| 125 | reg_no = reg_no, |
---|
[2157] | 126 | ds = ds |
---|
[2156] | 127 | ) |
---|
| 128 | |
---|
| 129 | |
---|