1 | ## $Id: browser.py 16874 2022-03-11 08:22:43Z 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.applicants.viewlets import ( |
---|
26 | PaymentReceiptActionButton, PDFActionButton) |
---|
27 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
28 | from waeup.kofa.interfaces import IKofaUtils |
---|
29 | from waeup.kofa.browser.interfaces import IPDFCreator |
---|
30 | from waeup.kofa.applicants.workflow import ( |
---|
31 | SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) |
---|
32 | |
---|
33 | from kofacustom.nigeria.applicants.browser import ( |
---|
34 | NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage, |
---|
35 | NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage) |
---|
36 | |
---|
37 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
38 | |
---|
39 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
40 | UG_OMIT_DISPLAY_FIELDS, |
---|
41 | UG_OMIT_PDF_FIELDS, |
---|
42 | UG_OMIT_MANAGE_FIELDS, |
---|
43 | UG_OMIT_EDIT_FIELDS |
---|
44 | ) |
---|
45 | from waeup.fceokene.applicants.interfaces import ( |
---|
46 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
47 | BEC_OMIT_DISPLAY_FIELDS, |
---|
48 | BEC_OMIT_PDF_FIELDS, |
---|
49 | BEC_OMIT_MANAGE_FIELDS, |
---|
50 | BEC_OMIT_EDIT_FIELDS, |
---|
51 | ITPURegistration |
---|
52 | ) |
---|
53 | |
---|
54 | UG_OMIT_EDIT_FIELDS = [ |
---|
55 | value for value in UG_OMIT_EDIT_FIELDS |
---|
56 | if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')] |
---|
57 | |
---|
58 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
59 | """A display view for applicant data. |
---|
60 | """ |
---|
61 | |
---|
62 | @property |
---|
63 | def form_fields(self): |
---|
64 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
65 | if target == 'tpu': |
---|
66 | form_fields = grok.AutoFields(ITPURegistration).omit( |
---|
67 | 'locked', 'suspended') |
---|
68 | return form_fields |
---|
69 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
70 | if target is not None and target.startswith('bec'): |
---|
71 | for field in BEC_OMIT_DISPLAY_FIELDS: |
---|
72 | form_fields = form_fields.omit(field) |
---|
73 | else: |
---|
74 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
75 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
76 | form_fields = form_fields.omit(field) |
---|
77 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
78 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
79 | if not getattr(self.context, 'student_id'): |
---|
80 | form_fields = form_fields.omit('student_id') |
---|
81 | if not getattr(self.context, 'screening_score'): |
---|
82 | form_fields = form_fields.omit('screening_score') |
---|
83 | if not getattr(self.context, 'screening_venue'): |
---|
84 | form_fields = form_fields.omit('screening_venue') |
---|
85 | if not getattr(self.context, 'screening_date'): |
---|
86 | form_fields = form_fields.omit('screening_date') |
---|
87 | return form_fields |
---|
88 | |
---|
89 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
90 | |
---|
91 | def _reduced_slip(self): |
---|
92 | return getattr(self.context, 'result_uploaded', False) |
---|
93 | |
---|
94 | def _getPDFCreator(self): |
---|
95 | if 'putme' in self.target or 'pude' in self.target: |
---|
96 | return getUtility(IPDFCreator, name='ibadan_pdfcreator') |
---|
97 | return getUtility(IPDFCreator) |
---|
98 | |
---|
99 | @property |
---|
100 | def title(self): |
---|
101 | container_title = self.context.__parent__.title |
---|
102 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
103 | ar_translation = translate(_('Application Record'), |
---|
104 | 'waeup.kofa', target_language=portal_language) |
---|
105 | if 'putme' in self.target or 'pude' in self.target: |
---|
106 | return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % ( |
---|
107 | container_title, ar_translation, |
---|
108 | self.context.application_number) |
---|
109 | return '%s - %s %s' % (container_title, |
---|
110 | ar_translation, self.context.application_number) |
---|
111 | |
---|
112 | |
---|
113 | @property |
---|
114 | def form_fields(self): |
---|
115 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
116 | if target == 'tpu': |
---|
117 | form_fields = grok.AutoFields(ITPURegistration).omit( |
---|
118 | 'locked', 'suspended') |
---|
119 | return form_fields |
---|
120 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
121 | if target is not None and target.startswith('bec'): |
---|
122 | for field in BEC_OMIT_PDF_FIELDS: |
---|
123 | form_fields = form_fields.omit(field) |
---|
124 | else: |
---|
125 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
126 | for field in UG_OMIT_PDF_FIELDS: |
---|
127 | form_fields = form_fields.omit(field) |
---|
128 | if not getattr(self.context, 'student_id'): |
---|
129 | form_fields = form_fields.omit('student_id') |
---|
130 | if not getattr(self.context, 'screening_score'): |
---|
131 | form_fields = form_fields.omit('screening_score') |
---|
132 | if not getattr(self.context, 'screening_venue'): |
---|
133 | form_fields = form_fields.omit('screening_venue') |
---|
134 | if not getattr(self.context, 'screening_date'): |
---|
135 | form_fields = form_fields.omit('screening_date') |
---|
136 | return form_fields |
---|
137 | |
---|
138 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
139 | """A full edit view for applicant data. |
---|
140 | """ |
---|
141 | |
---|
142 | @property |
---|
143 | def form_fields(self): |
---|
144 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
145 | if target == 'tpu': |
---|
146 | form_fields = grok.AutoFields(ITPURegistration) |
---|
147 | form_fields['applicant_id'].for_display = True |
---|
148 | return form_fields |
---|
149 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
150 | if target is not None and target.startswith('bec'): |
---|
151 | for field in BEC_OMIT_MANAGE_FIELDS: |
---|
152 | form_fields = form_fields.omit(field) |
---|
153 | else: |
---|
154 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
155 | form_fields = form_fields.omit(field) |
---|
156 | form_fields['student_id'].for_display = True |
---|
157 | form_fields['applicant_id'].for_display = True |
---|
158 | return form_fields |
---|
159 | |
---|
160 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
161 | """An applicant-centered edit view for applicant data. |
---|
162 | """ |
---|
163 | |
---|
164 | @property |
---|
165 | def form_fields(self): |
---|
166 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
167 | if target == 'tpu': |
---|
168 | form_fields = grok.AutoFields(ITPURegistration).omit( |
---|
169 | 'locked', 'suspended') |
---|
170 | form_fields['applicant_id'].for_display = True |
---|
171 | form_fields['reg_number'].for_display = True |
---|
172 | form_fields['firstname'].for_display = True |
---|
173 | form_fields['middlename'].for_display = True |
---|
174 | form_fields['lastname'].for_display = True |
---|
175 | form_fields['lga'].for_display = True |
---|
176 | form_fields['matric_number'].for_display = True |
---|
177 | return form_fields |
---|
178 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
179 | if target is not None and target.startswith('bec'): |
---|
180 | for field in BEC_OMIT_EDIT_FIELDS: |
---|
181 | form_fields = form_fields.omit(field) |
---|
182 | else: |
---|
183 | for field in UG_OMIT_EDIT_FIELDS: |
---|
184 | form_fields = form_fields.omit(field) |
---|
185 | form_fields['applicant_id'].for_display = True |
---|
186 | form_fields['reg_number'].for_display = True |
---|
187 | return form_fields |
---|
188 | |
---|
189 | def _student_per_school_exceeded(self, data): |
---|
190 | container = self.context.__parent__ |
---|
191 | counter = 0 |
---|
192 | for appl in container.values(): |
---|
193 | if appl != self.context \ |
---|
194 | and appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED): |
---|
195 | if appl.school1 == data.get('school1'): |
---|
196 | counter += 1 |
---|
197 | if appl.subj_comb == data.get('subj_comb'): |
---|
198 | return True |
---|
199 | if counter == 10: |
---|
200 | return True |
---|
201 | return False |
---|
202 | |
---|
203 | def dataNotComplete(self, data): |
---|
204 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
205 | if target == 'tpu': |
---|
206 | if self._student_per_school_exceeded(data): |
---|
207 | return ("1st Choice TPZ and School: " |
---|
208 | "Maximum number of applications per school exceeded. " |
---|
209 | "Please select another first choice school.") |
---|
210 | super(CustomApplicantEditFormPage, self).dataNotComplete(data) |
---|
211 | return |
---|