1 | ## $Id: browser.py 10088 2013-04-22 05:20:58Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """UI components for basic applicants and related components. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
22 | from waeup.futminna.applicants.interfaces import ( |
---|
23 | ICustomUGApplicant, |
---|
24 | ICustomPGApplicant, |
---|
25 | ICustomPGApplicantEdit, |
---|
26 | ICustomUGApplicantEdit, |
---|
27 | UG_OMIT_DISPLAY_FIELDS, |
---|
28 | UG_OMIT_PDF_FIELDS, |
---|
29 | UG_OMIT_MANAGE_FIELDS, |
---|
30 | UG_OMIT_EDIT_FIELDS, |
---|
31 | PG_OMIT_DISPLAY_FIELDS, |
---|
32 | PG_OMIT_PDF_FIELDS, |
---|
33 | PG_OMIT_MANAGE_FIELDS, |
---|
34 | PG_OMIT_EDIT_FIELDS, |
---|
35 | ) |
---|
36 | from kofacustom.nigeria.applicants.browser import ( |
---|
37 | NigeriaApplicantDisplayFormPage, |
---|
38 | NigeriaApplicantManageFormPage, |
---|
39 | NigeriaApplicantEditFormPage, |
---|
40 | NigeriaPDFApplicationSlip) |
---|
41 | |
---|
42 | |
---|
43 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
44 | """A display view for applicant data. |
---|
45 | """ |
---|
46 | |
---|
47 | grok.template('applicantdisplaypage') |
---|
48 | |
---|
49 | @property |
---|
50 | def form_fields(self): |
---|
51 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
52 | if target is not None and target.startswith('pg'): |
---|
53 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
54 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
55 | form_fields = form_fields.omit(field) |
---|
56 | else: |
---|
57 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
58 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
59 | form_fields = form_fields.omit(field) |
---|
60 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
61 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
62 | if not getattr(self.context, 'student_id'): |
---|
63 | form_fields = form_fields.omit('student_id') |
---|
64 | if not getattr(self.context, 'screening_score'): |
---|
65 | form_fields = form_fields.omit('screening_score') |
---|
66 | if not getattr(self.context, 'screening_venue'): |
---|
67 | form_fields = form_fields.omit('screening_venue') |
---|
68 | if not getattr(self.context, 'screening_date'): |
---|
69 | form_fields = form_fields.omit('screening_date') |
---|
70 | return form_fields |
---|
71 | |
---|
72 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
73 | |
---|
74 | @property |
---|
75 | def form_fields(self): |
---|
76 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
77 | if target is not None and target.startswith('pg'): |
---|
78 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
79 | for field in PG_OMIT_PDF_FIELDS: |
---|
80 | form_fields = form_fields.omit(field) |
---|
81 | else: |
---|
82 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
83 | for field in UG_OMIT_PDF_FIELDS: |
---|
84 | form_fields = form_fields.omit(field) |
---|
85 | if not getattr(self.context, 'student_id'): |
---|
86 | form_fields = form_fields.omit('student_id') |
---|
87 | if not getattr(self.context, 'screening_score'): |
---|
88 | form_fields = form_fields.omit('screening_score') |
---|
89 | if not getattr(self.context, 'screening_venue'): |
---|
90 | form_fields = form_fields.omit('screening_venue') |
---|
91 | if not getattr(self.context, 'screening_date'): |
---|
92 | form_fields = form_fields.omit('screening_date') |
---|
93 | return form_fields |
---|
94 | |
---|
95 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
96 | """A full edit view for applicant data. |
---|
97 | """ |
---|
98 | |
---|
99 | @property |
---|
100 | def form_fields(self): |
---|
101 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
102 | if target is not None and target.startswith('pg'): |
---|
103 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
104 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
105 | form_fields = form_fields.omit(field) |
---|
106 | else: |
---|
107 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
108 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
109 | form_fields = form_fields.omit(field) |
---|
110 | form_fields['student_id'].for_display = True |
---|
111 | form_fields['applicant_id'].for_display = True |
---|
112 | return form_fields |
---|
113 | |
---|
114 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
115 | """An applicant-centered edit view for applicant data. |
---|
116 | """ |
---|
117 | |
---|
118 | @property |
---|
119 | def form_fields(self): |
---|
120 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
121 | if target is not None and target.startswith('pg'): |
---|
122 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
123 | for field in PG_OMIT_EDIT_FIELDS: |
---|
124 | form_fields = form_fields.omit(field) |
---|
125 | else: |
---|
126 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
127 | for field in UG_OMIT_EDIT_FIELDS: |
---|
128 | form_fields = form_fields.omit(field) |
---|
129 | form_fields['applicant_id'].for_display = True |
---|
130 | form_fields['reg_number'].for_display = True |
---|
131 | return form_fields |
---|