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