1 | ## $Id: browser.py 15027 2018-05-28 07:16:26Z 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 CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
139 | """Deliver a PDF slip of the context. |
---|
140 | """ |
---|
141 | |
---|
142 | note = ''' |
---|
143 | |
---|
144 | |
---|
145 | The total authorized amount includes an Interswitch transaction charge of 150 Nairas. |
---|
146 | ''' |
---|
147 | |
---|
148 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
149 | """A full edit view for applicant data. |
---|
150 | """ |
---|
151 | |
---|
152 | @property |
---|
153 | def form_fields(self): |
---|
154 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
155 | if target == 'tpu': |
---|
156 | form_fields = grok.AutoFields(ITPURegistration) |
---|
157 | form_fields['applicant_id'].for_display = True |
---|
158 | return form_fields |
---|
159 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
160 | if target is not None and target.startswith('bec'): |
---|
161 | for field in BEC_OMIT_MANAGE_FIELDS: |
---|
162 | form_fields = form_fields.omit(field) |
---|
163 | else: |
---|
164 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
165 | form_fields = form_fields.omit(field) |
---|
166 | form_fields['student_id'].for_display = True |
---|
167 | form_fields['applicant_id'].for_display = True |
---|
168 | return form_fields |
---|
169 | |
---|
170 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
171 | """An applicant-centered edit view for applicant data. |
---|
172 | """ |
---|
173 | |
---|
174 | @property |
---|
175 | def form_fields(self): |
---|
176 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
177 | if target == 'tpu': |
---|
178 | form_fields = grok.AutoFields(ITPURegistration).omit( |
---|
179 | 'locked', 'suspended') |
---|
180 | form_fields['applicant_id'].for_display = True |
---|
181 | form_fields['reg_number'].for_display = True |
---|
182 | form_fields['firstname'].for_display = True |
---|
183 | form_fields['middlename'].for_display = True |
---|
184 | form_fields['lastname'].for_display = True |
---|
185 | form_fields['lga'].for_display = True |
---|
186 | form_fields['matric_number'].for_display = True |
---|
187 | return form_fields |
---|
188 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
189 | if target is not None and target.startswith('bec'): |
---|
190 | for field in BEC_OMIT_EDIT_FIELDS: |
---|
191 | form_fields = form_fields.omit(field) |
---|
192 | else: |
---|
193 | for field in UG_OMIT_EDIT_FIELDS: |
---|
194 | form_fields = form_fields.omit(field) |
---|
195 | form_fields['applicant_id'].for_display = True |
---|
196 | form_fields['reg_number'].for_display = True |
---|
197 | return form_fields |
---|
198 | |
---|
199 | @property |
---|
200 | def _student_per_school_exceeded(self): |
---|
201 | container = self.context.__parent__ |
---|
202 | counter = 0 |
---|
203 | if self.context.school1: |
---|
204 | for appl in container.values(): |
---|
205 | if appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) \ |
---|
206 | and appl.school1 == self.context.school1: |
---|
207 | counter += 1 |
---|
208 | if counter == 10: |
---|
209 | return True |
---|
210 | return False |
---|
211 | |
---|
212 | def dataNotComplete(self): |
---|
213 | if self._student_per_school_exceeded: |
---|
214 | return ("1st Choice TPZ and School: " |
---|
215 | "Maximum number of applications per school exceeded. " |
---|
216 | "Please select another first choice school.") |
---|
217 | super(CustomApplicantEditFormPage, self).dataNotComplete() |
---|
218 | return |
---|