1 | ## $Id: browser.py 15947 2020-01-23 14:35:44Z 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 | import os |
---|
22 | from zope.component import getUtility |
---|
23 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
24 | from waeup.kofa.interfaces import ( |
---|
25 | IExtFileStore, IFileStoreNameChooser) |
---|
26 | from waeup.kofa.utils.helpers import string_from_bytes, file_size, now |
---|
27 | from waeup.kofa.applicants.browser import ( |
---|
28 | ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile) |
---|
29 | from waeup.kofa.applicants.interfaces import ( |
---|
30 | ISpecialApplicant, IApplicantsContainer) |
---|
31 | from kofacustom.nigeria.applicants.browser import ( |
---|
32 | NigeriaApplicantDisplayFormPage, |
---|
33 | NigeriaApplicantManageFormPage, |
---|
34 | NigeriaApplicantEditFormPage, |
---|
35 | NigeriaPDFApplicationSlip) |
---|
36 | from waeup.kofa.widgets.datewidget import ( |
---|
37 | FriendlyDateDisplayWidget, |
---|
38 | FriendlyDatetimeDisplayWidget) |
---|
39 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
40 | OMIT_DISPLAY_FIELDS, |
---|
41 | #UG_OMIT_DISPLAY_FIELDS, |
---|
42 | #UG_OMIT_PDF_FIELDS, |
---|
43 | #UG_OMIT_MANAGE_FIELDS, |
---|
44 | #UG_OMIT_EDIT_FIELDS, |
---|
45 | PG_OMIT_DISPLAY_FIELDS, |
---|
46 | PG_OMIT_PDF_FIELDS, |
---|
47 | PG_OMIT_MANAGE_FIELDS, |
---|
48 | PG_OMIT_EDIT_FIELDS, |
---|
49 | ) |
---|
50 | from kofacustom.iuokada.applicants.interfaces import ( |
---|
51 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
52 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
53 | ICustomApplicantOnlinePayment |
---|
54 | ) |
---|
55 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
56 | |
---|
57 | MAX_FILE_UPLOAD_SIZE = 1024 * 500 |
---|
58 | |
---|
59 | # UG students are all undergraduate students. |
---|
60 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
61 | #'jamb_subjects_list', |
---|
62 | 'programme_type',) |
---|
63 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
64 | UG_OMIT_MANAGE_FIELDS = ( |
---|
65 | 'special_application', |
---|
66 | #'jamb_subjects_list', |
---|
67 | 'programme_type') |
---|
68 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
69 | 'student_id', |
---|
70 | 'notice', |
---|
71 | 'screening_score', |
---|
72 | 'screening_venue', |
---|
73 | 'screening_date', |
---|
74 | #'jamb_age', |
---|
75 | #'jamb_subjects', |
---|
76 | #'jamb_score', |
---|
77 | #'jamb_reg_number', |
---|
78 | 'aggregate') |
---|
79 | |
---|
80 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
81 | """The standard view for regular applicant containers. |
---|
82 | """ |
---|
83 | |
---|
84 | @property |
---|
85 | def form_fields(self): |
---|
86 | form_fields = grok.AutoFields(IApplicantsContainer).omit( |
---|
87 | 'title', 'description') |
---|
88 | if self.request.principal.id == 'zope.anybody': |
---|
89 | form_fields = form_fields.omit( |
---|
90 | 'code', 'prefix', 'year', 'mode', 'hidden', |
---|
91 | 'strict_deadline', 'application_category', |
---|
92 | 'application_slip_notice', |
---|
93 | 'application_fee', 'with_picture', |
---|
94 | 'startdate', 'enddate') |
---|
95 | return form_fields |
---|
96 | |
---|
97 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
98 | """A display view for applicant data. |
---|
99 | """ |
---|
100 | |
---|
101 | @property |
---|
102 | def form_fields(self): |
---|
103 | if self.target is not None and self.target.startswith('pg'): |
---|
104 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
105 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
106 | form_fields = form_fields.omit(field) |
---|
107 | else: |
---|
108 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
109 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
110 | form_fields = form_fields.omit(field) |
---|
111 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
112 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
113 | if not getattr(self.context, 'student_id'): |
---|
114 | form_fields = form_fields.omit('student_id') |
---|
115 | if not getattr(self.context, 'screening_score'): |
---|
116 | form_fields = form_fields.omit('screening_score') |
---|
117 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
118 | form_fields = form_fields.omit('screening_venue') |
---|
119 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
120 | form_fields = form_fields.omit('screening_date') |
---|
121 | return form_fields |
---|
122 | |
---|
123 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
124 | """A full edit view for applicant data. |
---|
125 | """ |
---|
126 | |
---|
127 | @property |
---|
128 | def form_fields(self): |
---|
129 | if self.target is not None and self.target.startswith('pg'): |
---|
130 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
131 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
132 | form_fields = form_fields.omit(field) |
---|
133 | else: |
---|
134 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
135 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
136 | form_fields = form_fields.omit(field) |
---|
137 | form_fields['student_id'].for_display = True |
---|
138 | form_fields['applicant_id'].for_display = True |
---|
139 | return form_fields |
---|
140 | |
---|
141 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
142 | """An applicant-centered edit view for applicant data. |
---|
143 | """ |
---|
144 | |
---|
145 | def display_fileupload(self, filename): |
---|
146 | if filename[1] == 'res_stat.pdf': |
---|
147 | if self.context.subtype != 'transfer': |
---|
148 | return False |
---|
149 | return True |
---|
150 | |
---|
151 | def dataNotComplete(self, data): |
---|
152 | store = getUtility(IExtFileStore) |
---|
153 | if self.context.__parent__.with_picture: |
---|
154 | store = getUtility(IExtFileStore) |
---|
155 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
156 | return _('No passport picture uploaded.') |
---|
157 | if not self.request.form.get('confirm_passport', False): |
---|
158 | return _('Passport picture confirmation box not ticked.') |
---|
159 | if self.context.subtype == 'transfer' and \ |
---|
160 | not store.getFileByContext(self.context, attr=u'res_stat.pdf'): |
---|
161 | return _('No statement of result pdf file uploaded.') |
---|
162 | return False |
---|
163 | |
---|
164 | @property |
---|
165 | def form_fields(self): |
---|
166 | if self.target is not None and self.target.startswith('pg'): |
---|
167 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
168 | for field in PG_OMIT_EDIT_FIELDS: |
---|
169 | form_fields = form_fields.omit(field) |
---|
170 | else: |
---|
171 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
172 | for field in UG_OMIT_EDIT_FIELDS: |
---|
173 | form_fields = form_fields.omit(field) |
---|
174 | form_fields['applicant_id'].for_display = True |
---|
175 | form_fields['reg_number'].for_display = True |
---|
176 | return form_fields |
---|
177 | |
---|
178 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
179 | |
---|
180 | @property |
---|
181 | def form_fields(self): |
---|
182 | if self.target is not None and self.target.startswith('pg'): |
---|
183 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
184 | for field in PG_OMIT_PDF_FIELDS: |
---|
185 | form_fields = form_fields.omit(field) |
---|
186 | else: |
---|
187 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
188 | for field in UG_OMIT_PDF_FIELDS: |
---|
189 | form_fields = form_fields.omit(field) |
---|
190 | if not getattr(self.context, 'student_id'): |
---|
191 | form_fields = form_fields.omit('student_id') |
---|
192 | if not getattr(self.context, 'screening_score'): |
---|
193 | form_fields = form_fields.omit('screening_score') |
---|
194 | if not getattr(self.context, 'screening_venue'): |
---|
195 | form_fields = form_fields.omit('screening_venue') |
---|
196 | if not getattr(self.context, 'screening_date'): |
---|
197 | form_fields = form_fields.omit('screening_date') |
---|
198 | return form_fields |
---|
199 | |
---|
200 | class ResultStatement(AdditionalFile): |
---|
201 | """Renders the pdf form extension for applicants. |
---|
202 | """ |
---|
203 | grok.name('res_stat.pdf') |
---|
204 | |
---|
205 | class JAMBResult(AdditionalFile): |
---|
206 | """Renders the pdf form extension for applicants. |
---|
207 | """ |
---|
208 | grok.name('jamb.pdf') |
---|