1 | ## $Id: browser.py 16853 2022-03-01 11:28:39Z 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, |
---|
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 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
97 | """A display view for applicant data. |
---|
98 | """ |
---|
99 | |
---|
100 | @property |
---|
101 | def form_fields(self): |
---|
102 | if self.target is not None and self.target.startswith('pg'): |
---|
103 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
104 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
105 | form_fields = form_fields.omit(field) |
---|
106 | else: |
---|
107 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
108 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
109 | form_fields = form_fields.omit(field) |
---|
110 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
111 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
112 | if not getattr(self.context, 'student_id'): |
---|
113 | form_fields = form_fields.omit('student_id') |
---|
114 | if not getattr(self.context, 'screening_score'): |
---|
115 | form_fields = form_fields.omit('screening_score') |
---|
116 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
117 | form_fields = form_fields.omit('screening_venue') |
---|
118 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
119 | form_fields = form_fields.omit('screening_date') |
---|
120 | if not getattr(self.context, 'cbt_score'): |
---|
121 | form_fields = form_fields.omit('cbt_score') |
---|
122 | if not getattr(self.context, 'cbt_venue') or self._not_paid(): |
---|
123 | form_fields = form_fields.omit('cbt_venue') |
---|
124 | if not getattr(self.context, 'cbt_date') or self._not_paid(): |
---|
125 | form_fields = form_fields.omit('cbt_date') |
---|
126 | return form_fields |
---|
127 | |
---|
128 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
129 | |
---|
130 | @property |
---|
131 | def form_fields(self): |
---|
132 | if self.target is not None and self.target.startswith('pg'): |
---|
133 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
134 | for field in PG_OMIT_PDF_FIELDS: |
---|
135 | form_fields = form_fields.omit(field) |
---|
136 | else: |
---|
137 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
138 | for field in UG_OMIT_PDF_FIELDS: |
---|
139 | form_fields = form_fields.omit(field) |
---|
140 | if not getattr(self.context, 'student_id'): |
---|
141 | form_fields = form_fields.omit('student_id') |
---|
142 | if not getattr(self.context, 'screening_score'): |
---|
143 | form_fields = form_fields.omit('screening_score') |
---|
144 | if not getattr(self.context, 'screening_venue'): |
---|
145 | form_fields = form_fields.omit('screening_venue') |
---|
146 | if not getattr(self.context, 'screening_date'): |
---|
147 | form_fields = form_fields.omit('screening_date') |
---|
148 | if not getattr(self.context, 'cbt_score'): |
---|
149 | form_fields = form_fields.omit('cbt_score') |
---|
150 | if not getattr(self.context, 'cbt_venue'): |
---|
151 | form_fields = form_fields.omit('cbt_venue') |
---|
152 | if not getattr(self.context, 'cbt_date'): |
---|
153 | form_fields = form_fields.omit('cbt_date') |
---|
154 | return form_fields |
---|
155 | |
---|
156 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
157 | """A full edit view for applicant data. |
---|
158 | """ |
---|
159 | |
---|
160 | @property |
---|
161 | def form_fields(self): |
---|
162 | if self.target is not None and self.target.startswith('pg'): |
---|
163 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
164 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
165 | form_fields = form_fields.omit(field) |
---|
166 | else: |
---|
167 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
168 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
169 | form_fields = form_fields.omit(field) |
---|
170 | form_fields['student_id'].for_display = True |
---|
171 | form_fields['applicant_id'].for_display = True |
---|
172 | return form_fields |
---|
173 | |
---|
174 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
175 | """An applicant-centered edit view for applicant data. |
---|
176 | """ |
---|
177 | |
---|
178 | def unremovable(self, ticket): |
---|
179 | return True |
---|
180 | |
---|
181 | @property |
---|
182 | def form_fields(self): |
---|
183 | if self.target is not None and self.target.startswith('pg'): |
---|
184 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
185 | for field in PG_OMIT_EDIT_FIELDS: |
---|
186 | form_fields = form_fields.omit(field) |
---|
187 | else: |
---|
188 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
189 | for field in UG_OMIT_EDIT_FIELDS: |
---|
190 | form_fields = form_fields.omit(field) |
---|
191 | form_fields['applicant_id'].for_display = True |
---|
192 | form_fields['reg_number'].for_display = True |
---|
193 | return form_fields |
---|