1 | ## $Id: browser.py 17029 2022-07-23 08:08:45Z 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.component import getUtility |
---|
22 | from zope.i18n import translate |
---|
23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
25 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
26 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
27 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
28 | ApplicantRegistrationPage, |
---|
29 | OnlinePaymentDisplayFormPage, |
---|
30 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
31 | ) |
---|
32 | from waeup.kofa.applicants.viewlets import ( |
---|
33 | PDFActionButton, PaymentReceiptActionButton) |
---|
34 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
35 | from kofacustom.nigeria.applicants.browser import ( |
---|
36 | NigeriaApplicantDisplayFormPage, |
---|
37 | NigeriaApplicantManageFormPage, |
---|
38 | NigeriaApplicantEditFormPage, |
---|
39 | NigeriaPDFApplicationSlip) |
---|
40 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
41 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
42 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
43 | INigeriaApplicantOnlinePayment, |
---|
44 | #UG_OMIT_DISPLAY_FIELDS, |
---|
45 | #UG_OMIT_PDF_FIELDS, |
---|
46 | #UG_OMIT_MANAGE_FIELDS, |
---|
47 | #UG_OMIT_EDIT_FIELDS, |
---|
48 | PG_OMIT_DISPLAY_FIELDS, |
---|
49 | PG_OMIT_PDF_FIELDS, |
---|
50 | PG_OMIT_MANAGE_FIELDS, |
---|
51 | PG_OMIT_EDIT_FIELDS, |
---|
52 | ) |
---|
53 | from kofacustom.edocons.applicants.interfaces import ( |
---|
54 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
55 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
56 | ICustomApplicantOnlinePayment, ITranscriptApplicant, |
---|
57 | ) |
---|
58 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
59 | |
---|
60 | # Fields to be omitted in all display forms. course_admitted is |
---|
61 | # rendered separately. |
---|
62 | |
---|
63 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
64 | 'result_uploaded', 'suspended', 'special_application', |
---|
65 | 'bank_account_number', |
---|
66 | 'bank_account_name', |
---|
67 | 'bank_name', |
---|
68 | #'course1', 'course2' # these 2 have been added and later removed again |
---|
69 | ) |
---|
70 | |
---|
71 | # UG students are all undergraduate students. |
---|
72 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
73 | 'jamb_subjects_list', 'programme_type') |
---|
74 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
75 | UG_OMIT_MANAGE_FIELDS = ( |
---|
76 | 'special_application', |
---|
77 | 'jamb_subjects_list', |
---|
78 | 'programme_type', |
---|
79 | #'course1', 'course2', # these 2 have been added and later removed again |
---|
80 | ) |
---|
81 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
82 | 'student_id', |
---|
83 | 'notice', |
---|
84 | 'screening_score', |
---|
85 | 'screening_venue', |
---|
86 | 'screening_date', |
---|
87 | 'cbt_score', |
---|
88 | 'cbt_venue', |
---|
89 | 'cbt_date', |
---|
90 | 'jamb_age', |
---|
91 | 'jamb_subjects', |
---|
92 | 'jamb_score', |
---|
93 | 'jamb_reg_number', |
---|
94 | 'aggregate') |
---|
95 | |
---|
96 | TSC_OMIT_FIELDS = ('locked', 'suspended', |
---|
97 | ) |
---|
98 | |
---|
99 | |
---|
100 | TSC_OMIT_EDIT_FIELDS = TSC_OMIT_FIELDS + ( |
---|
101 | 'applicant_id', |
---|
102 | 'proc_date', |
---|
103 | ) |
---|
104 | |
---|
105 | TSC_OMIT_MANAGE_FIELDS = TSC_OMIT_FIELDS + ( |
---|
106 | 'applicant_id',) |
---|
107 | |
---|
108 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
109 | """A display view for applicant data. |
---|
110 | """ |
---|
111 | |
---|
112 | @property |
---|
113 | def form_fields(self): |
---|
114 | if self.target is not None and self.target.startswith('pg'): |
---|
115 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
116 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
117 | form_fields = form_fields.omit(field) |
---|
118 | elif self.target is not None and self.target.startswith('tsc'): |
---|
119 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
120 | for field in TSC_OMIT_FIELDS: |
---|
121 | form_fields = form_fields.omit(field) |
---|
122 | return form_fields |
---|
123 | else: |
---|
124 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
125 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
126 | form_fields = form_fields.omit(field) |
---|
127 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
128 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
129 | if not getattr(self.context, 'student_id'): |
---|
130 | form_fields = form_fields.omit('student_id') |
---|
131 | if not getattr(self.context, 'screening_score'): |
---|
132 | form_fields = form_fields.omit('screening_score') |
---|
133 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
134 | form_fields = form_fields.omit('screening_venue') |
---|
135 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
136 | form_fields = form_fields.omit('screening_date') |
---|
137 | if not getattr(self.context, 'cbt_score'): |
---|
138 | form_fields = form_fields.omit('cbt_score') |
---|
139 | if not getattr(self.context, 'cbt_venue') or self._not_paid(): |
---|
140 | form_fields = form_fields.omit('cbt_venue') |
---|
141 | if not getattr(self.context, 'cbt_date') or self._not_paid(): |
---|
142 | form_fields = form_fields.omit('cbt_date') |
---|
143 | return form_fields |
---|
144 | |
---|
145 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
146 | |
---|
147 | @property |
---|
148 | def form_fields(self): |
---|
149 | if self.target is not None and self.target.startswith('pg'): |
---|
150 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
151 | for field in PG_OMIT_PDF_FIELDS: |
---|
152 | form_fields = form_fields.omit(field) |
---|
153 | elif self.target is not None and self.target.startswith('tsc'): |
---|
154 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
155 | for field in TSC_OMIT_FIELDS: |
---|
156 | form_fields = form_fields.omit(field) |
---|
157 | return form_fields |
---|
158 | else: |
---|
159 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
160 | for field in UG_OMIT_PDF_FIELDS: |
---|
161 | form_fields = form_fields.omit(field) |
---|
162 | if not getattr(self.context, 'student_id'): |
---|
163 | form_fields = form_fields.omit('student_id') |
---|
164 | if not getattr(self.context, 'screening_score'): |
---|
165 | form_fields = form_fields.omit('screening_score') |
---|
166 | if not getattr(self.context, 'screening_venue'): |
---|
167 | form_fields = form_fields.omit('screening_venue') |
---|
168 | if not getattr(self.context, 'screening_date'): |
---|
169 | form_fields = form_fields.omit('screening_date') |
---|
170 | if not getattr(self.context, 'cbt_score'): |
---|
171 | form_fields = form_fields.omit('cbt_score') |
---|
172 | if not getattr(self.context, 'cbt_venue'): |
---|
173 | form_fields = form_fields.omit('cbt_venue') |
---|
174 | if not getattr(self.context, 'cbt_date'): |
---|
175 | form_fields = form_fields.omit('cbt_date') |
---|
176 | return form_fields |
---|
177 | |
---|
178 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
179 | """A full edit view for applicant data. |
---|
180 | """ |
---|
181 | |
---|
182 | @property |
---|
183 | def form_fields(self): |
---|
184 | if self.target is not None and self.target.startswith('pg'): |
---|
185 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
186 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
187 | form_fields = form_fields.omit(field) |
---|
188 | elif self.target is not None and self.target.startswith('tsc'): |
---|
189 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
190 | for field in TSC_OMIT_MANAGE_FIELDS: |
---|
191 | form_fields = form_fields.omit(field) |
---|
192 | return form_fields |
---|
193 | else: |
---|
194 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
195 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
196 | form_fields = form_fields.omit(field) |
---|
197 | form_fields['student_id'].for_display = True |
---|
198 | form_fields['applicant_id'].for_display = True |
---|
199 | return form_fields |
---|
200 | |
---|
201 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
202 | """An applicant-centered edit view for applicant data. |
---|
203 | """ |
---|
204 | |
---|
205 | def unremovable(self, ticket): |
---|
206 | return True |
---|
207 | |
---|
208 | @property |
---|
209 | def form_fields(self): |
---|
210 | if self.target is not None and self.target.startswith('pg'): |
---|
211 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
212 | for field in PG_OMIT_EDIT_FIELDS: |
---|
213 | form_fields = form_fields.omit(field) |
---|
214 | elif self.target is not None and self.target.startswith('tsc'): |
---|
215 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
216 | for field in TSC_OMIT_EDIT_FIELDS: |
---|
217 | form_fields = form_fields.omit(field) |
---|
218 | return form_fields |
---|
219 | else: |
---|
220 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
221 | for field in UG_OMIT_EDIT_FIELDS: |
---|
222 | form_fields = form_fields.omit(field) |
---|
223 | form_fields['applicant_id'].for_display = True |
---|
224 | form_fields['reg_number'].for_display = True |
---|
225 | return form_fields |
---|