[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 2225 2007-09-12 21:04:51Z 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(): |
---|
[2217] | 33 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.absolute_url()) |
---|
[2158] | 34 | |
---|
[2156] | 35 | #type_name = 'StudentApplication' |
---|
| 36 | #ti = context.portal_types[type_name] |
---|
| 37 | #REQUEST.set('type_name',type_name) |
---|
[2169] | 38 | |
---|
| 39 | search = "search" in request.keys() |
---|
[2156] | 40 | reset = "reset" in request.keys() |
---|
[2168] | 41 | edit = "edit" in request.keys() |
---|
[2156] | 42 | lt = context.portal_layouts |
---|
[2157] | 43 | |
---|
[2160] | 44 | reg_no = request.get('reg_no','').upper() |
---|
| 45 | new_reg_no = request.get('new_reg_no','').upper() |
---|
[2157] | 46 | |
---|
[2168] | 47 | if reset or edit: |
---|
[2157] | 48 | reg_no = reg_no |
---|
| 49 | elif new_reg_no: |
---|
| 50 | reg_no = new_reg_no |
---|
| 51 | |
---|
[2156] | 52 | res = '' |
---|
| 53 | psm = '' |
---|
| 54 | object = {} |
---|
[2168] | 55 | ds = [] |
---|
[2170] | 56 | found = False |
---|
[2168] | 57 | |
---|
[2169] | 58 | validate = not search |
---|
| 59 | |
---|
[2168] | 60 | if reg_no: |
---|
| 61 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
[2170] | 62 | |
---|
[2168] | 63 | if len(brains) == 1: |
---|
[2170] | 64 | found = True |
---|
[2168] | 65 | for field in context.applicants_catalog.schema(): |
---|
| 66 | object[field] = getattr(brains[0],field,None) |
---|
| 67 | res,psm,ds = lt.renderLayout(layout_id= 'application_manage', |
---|
| 68 | schema_id= 'application', |
---|
| 69 | layout_mode = "edit", |
---|
| 70 | context=context, |
---|
[2169] | 71 | mapping=validate and REQUEST, |
---|
[2168] | 72 | ob=object, |
---|
| 73 | commit = False, |
---|
| 74 | ) |
---|
[2170] | 75 | |
---|
| 76 | |
---|
[2168] | 77 | if psm == 'invalid': |
---|
| 78 | return context.apply_pume_manage_form(rendered = res, |
---|
| 79 | psm = "Please correct your input!", |
---|
| 80 | #psm = "%s, %s" % (psm,ds), |
---|
| 81 | ds = ds, |
---|
| 82 | ) |
---|
| 83 | elif psm == '': |
---|
[2170] | 84 | if search and not found: |
---|
| 85 | psm = 'Registration Number not found!' |
---|
[2168] | 86 | return context.apply_pume_manage_form(rendered = res, |
---|
| 87 | psm = psm, |
---|
[2222] | 88 | reg_no = reg_no, |
---|
[2168] | 89 | ds = ds, |
---|
| 90 | ) |
---|
| 91 | elif psm == 'valid': |
---|
| 92 | psm = '' |
---|
| 93 | pass |
---|
[2170] | 94 | |
---|
[2156] | 95 | data = {} |
---|
[2168] | 96 | dm = ds.getDataModel() |
---|
| 97 | for field in context.applicants_catalog.schema(): |
---|
| 98 | if dm.has_key("%s" % field): |
---|
| 99 | data[field] = dm.get(field) |
---|
| 100 | |
---|
| 101 | |
---|
[2156] | 102 | if reset and reg_no: |
---|
[2168] | 103 | #data['reg_no'] = reg_no |
---|
[2157] | 104 | psm = "You successfully reset the record! The applicant will be able to edit and resubmit the data." |
---|
[2161] | 105 | data['status'] = "reset" |
---|
[2156] | 106 | context.applicants_catalog.modifyRecord(**data) |
---|
| 107 | logger.info('%s reset application record of %s' % (member,reg_no)) |
---|
[2222] | 108 | |
---|
[2168] | 109 | if edit and reg_no: |
---|
| 110 | #data['reg_no'] = reg_no |
---|
| 111 | psm = "Content changed!" |
---|
| 112 | context.applicants_catalog.modifyRecord(**data) |
---|
| 113 | logger.info('%s edited application record of %s' % (member,reg_no)) |
---|
| 114 | |
---|
[2158] | 115 | |
---|
[2225] | 116 | brains = context.applicants_catalog(reg_no = reg_no) |
---|
[2170] | 117 | for field in context.applicants_catalog.schema(): |
---|
| 118 | object[field] = getattr(brains[0],field,None) |
---|
[2168] | 119 | |
---|
[2170] | 120 | res,psm_dummy,ds = lt.renderLayout(layout_id= 'application_manage', |
---|
| 121 | schema_id= 'application', |
---|
| 122 | layout_mode = "edit", |
---|
| 123 | context=context, |
---|
| 124 | ob=object, |
---|
| 125 | commit = False, |
---|
| 126 | ) |
---|
[2158] | 127 | |
---|
[2217] | 128 | |
---|
[2156] | 129 | return context.apply_pume_manage_form(rendered = res, |
---|
| 130 | psm = psm, |
---|
| 131 | reg_no = reg_no, |
---|
[2157] | 132 | ds = ds |
---|
[2156] | 133 | ) |
---|
| 134 | |
---|
| 135 | |
---|