1 | ## $Id: browser.py 13544 2015-12-16 06:07:20Z 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 waeup.kofa.interfaces import ( |
---|
24 | IExtFileStore, IFileStoreNameChooser) |
---|
25 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
26 | from waeup.kofa.utils.helpers import string_from_bytes, file_size |
---|
27 | from waeup.kofa.applicants.browser import ApplicantCheckStatusPage |
---|
28 | from waeup.kofa.applicants.viewlets import PDFActionButton |
---|
29 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
30 | from kofacustom.nigeria.applicants.browser import ( |
---|
31 | NigeriaApplicantDisplayFormPage, |
---|
32 | NigeriaApplicantManageFormPage, |
---|
33 | NigeriaApplicantEditFormPage, |
---|
34 | NigeriaPDFApplicationSlip, |
---|
35 | NigeriaApplicantRegistrationPage, |
---|
36 | NigeriaExportPDFPaymentSlipPage, |
---|
37 | UG_OMIT_DISPLAY_FIELDS, |
---|
38 | UG_OMIT_PDF_FIELDS, |
---|
39 | UG_OMIT_MANAGE_FIELDS, |
---|
40 | UG_OMIT_EDIT_FIELDS) |
---|
41 | from waeup.aaue.applicants.interfaces import ( |
---|
42 | ICustomUGApplicant, |
---|
43 | ICustomUGApplicantEdit, |
---|
44 | ITranscriptApplicant |
---|
45 | ) |
---|
46 | |
---|
47 | UG_OMIT_PDF_FIELDS = tuple([ |
---|
48 | element for element in UG_OMIT_PDF_FIELDS if not element == 'phone']) |
---|
49 | UG_OMIT_PDF_FIELDS += ('reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
50 | 'alr_results', 'notice') |
---|
51 | |
---|
52 | FP_OMIT_FIELDS = ('hq_type', 'hq_fname', 'hq_matric_no', |
---|
53 | 'hq_degree', 'hq_school', 'hq_session', 'hq_disc') |
---|
54 | FP_OMIT_DISPLAY_FIELDS = UG_OMIT_DISPLAY_FIELDS + FP_OMIT_FIELDS |
---|
55 | FP_OMIT_PDF_FIELDS = UG_OMIT_PDF_FIELDS + FP_OMIT_FIELDS |
---|
56 | FP_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + FP_OMIT_FIELDS |
---|
57 | FP_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + FP_OMIT_FIELDS |
---|
58 | |
---|
59 | PG_OMIT_FIELDS = ('programme_type',) |
---|
60 | PG_OMIT_DISPLAY_FIELDS = UG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS |
---|
61 | PG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS |
---|
62 | PG_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + PG_OMIT_FIELDS |
---|
63 | PG_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + PG_OMIT_FIELDS |
---|
64 | |
---|
65 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
66 | """A display view for applicant data. |
---|
67 | """ |
---|
68 | |
---|
69 | @property |
---|
70 | def form_fields(self): |
---|
71 | if self.target is not None and self.target == 'trans': |
---|
72 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
73 | 'locked', 'suspended') |
---|
74 | form_fields['dispatch_address'].custom_widget = BytesDisplayWidget |
---|
75 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
76 | return form_fields |
---|
77 | # AAUE is using the same interface for all regular applications. |
---|
78 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
79 | if self.target is not None and self.target.startswith('pg'): |
---|
80 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
81 | form_fields = form_fields.omit(field) |
---|
82 | elif self.target is not None and self.target.startswith('fp'): |
---|
83 | for field in FP_OMIT_DISPLAY_FIELDS: |
---|
84 | form_fields = form_fields.omit(field) |
---|
85 | else: |
---|
86 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
87 | form_fields = form_fields.omit(field) |
---|
88 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
89 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
90 | if not getattr(self.context, 'student_id'): |
---|
91 | form_fields = form_fields.omit('student_id') |
---|
92 | if not getattr(self.context, 'screening_score'): |
---|
93 | form_fields = form_fields.omit('screening_score') |
---|
94 | if not getattr(self.context, 'screening_venue'): |
---|
95 | form_fields = form_fields.omit('screening_venue') |
---|
96 | if not getattr(self.context, 'screening_date'): |
---|
97 | form_fields = form_fields.omit('screening_date') |
---|
98 | return form_fields |
---|
99 | |
---|
100 | class CustomPDFActionButton(PDFActionButton): |
---|
101 | |
---|
102 | @property |
---|
103 | def target_url(self): |
---|
104 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
105 | or self.context.special or self.view.target == 'trans': |
---|
106 | return |
---|
107 | return self.view.url(self.view.context, self.target) |
---|
108 | |
---|
109 | |
---|
110 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
111 | |
---|
112 | column_two_fields = ('applicant_id', 'reg_number', |
---|
113 | 'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth') |
---|
114 | two_columns_design_fields = [ |
---|
115 | 'fst_sit_fname', 'fst_sit_no', 'fst_sit_date', |
---|
116 | 'fst_sit_type', 'fst_sit_results', |
---|
117 | 'scd_sit_fname', 'scd_sit_no', 'scd_sit_date', |
---|
118 | 'scd_sit_type', 'scd_sit_results'] |
---|
119 | |
---|
120 | @property |
---|
121 | def note(self): |
---|
122 | if self.context.sex == 'm': |
---|
123 | pronoun = 'he' |
---|
124 | else: |
---|
125 | pronoun = 'she' |
---|
126 | return ''' |
---|
127 | The applicant has acknowledged that, if discovered at any time that %s does not possess |
---|
128 | any of the qualifications which %s claims %s has obtained, %s will be expelled from the |
---|
129 | University not be re-admitted for the same or any other programme, even if %s has |
---|
130 | upgraded previous and shall qualifications or possess additional qualifications. |
---|
131 | ''' % ( |
---|
132 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
133 | |
---|
134 | @property |
---|
135 | def form_fields(self): |
---|
136 | # AAUE is using the same interface for all regular applications. |
---|
137 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
138 | if self.target is not None and self.target.startswith('pg'): |
---|
139 | for field in PG_OMIT_PDF_FIELDS: |
---|
140 | form_fields = form_fields.omit(field) |
---|
141 | elif self.target is not None and self.target.startswith('fp'): |
---|
142 | for field in FP_OMIT_PDF_FIELDS: |
---|
143 | form_fields = form_fields.omit(field) |
---|
144 | else: |
---|
145 | for field in UG_OMIT_PDF_FIELDS: |
---|
146 | form_fields = form_fields.omit(field) |
---|
147 | if not getattr(self.context, 'student_id'): |
---|
148 | form_fields = form_fields.omit('student_id') |
---|
149 | if not getattr(self.context, 'screening_score'): |
---|
150 | form_fields = form_fields.omit('screening_score') |
---|
151 | if not getattr(self.context, 'screening_venue'): |
---|
152 | form_fields = form_fields.omit('screening_venue') |
---|
153 | if not getattr(self.context, 'screening_date'): |
---|
154 | form_fields = form_fields.omit('screening_date') |
---|
155 | return form_fields |
---|
156 | |
---|
157 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
158 | """A full edit view for applicant data. |
---|
159 | """ |
---|
160 | |
---|
161 | @property |
---|
162 | def form_fields(self): |
---|
163 | if self.target is not None and self.target == 'trans': |
---|
164 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
165 | form_fields['applicant_id'].for_display = True |
---|
166 | return form_fields |
---|
167 | # AAUE is using the same interface for all regular applications. |
---|
168 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
169 | if self.target is not None and self.target.startswith('pg'): |
---|
170 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
171 | form_fields = form_fields.omit(field) |
---|
172 | elif self.target is not None and self.target.startswith('fp'): |
---|
173 | for field in FP_OMIT_MANAGE_FIELDS: |
---|
174 | form_fields = form_fields.omit(field) |
---|
175 | else: |
---|
176 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
177 | form_fields = form_fields.omit(field) |
---|
178 | form_fields['student_id'].for_display = True |
---|
179 | form_fields['applicant_id'].for_display = True |
---|
180 | return form_fields |
---|
181 | |
---|
182 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
183 | """An applicant-centered edit view for applicant data. |
---|
184 | """ |
---|
185 | |
---|
186 | grok.template('transcriptapplicanteditpage') |
---|
187 | |
---|
188 | @property |
---|
189 | def form_fields(self): |
---|
190 | if self.target is not None and self.target == 'trans': |
---|
191 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
192 | 'locked', 'suspended') |
---|
193 | form_fields['applicant_id'].for_display = True |
---|
194 | return form_fields |
---|
195 | # AAUE is using the same interface for all regular applications. |
---|
196 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
197 | if self.target is not None and self.target.startswith('pg'): |
---|
198 | for field in PG_OMIT_EDIT_FIELDS: |
---|
199 | form_fields = form_fields.omit(field) |
---|
200 | elif self.target is not None and self.target.startswith('fp'): |
---|
201 | for field in FP_OMIT_EDIT_FIELDS: |
---|
202 | form_fields = form_fields.omit(field) |
---|
203 | else: |
---|
204 | for field in UG_OMIT_EDIT_FIELDS: |
---|
205 | form_fields = form_fields.omit(field) |
---|
206 | form_fields['applicant_id'].for_display = True |
---|
207 | form_fields['reg_number'].for_display = True |
---|
208 | return form_fields |
---|
209 | |
---|
210 | class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage): |
---|
211 | """Captcha'd registration page for applicants. |
---|
212 | """ |
---|
213 | |
---|
214 | def _redirect(self, email, password, applicant_id): |
---|
215 | # Forward email and credentials to landing page. |
---|
216 | self.redirect(self.url(self.context, 'registration_complete', |
---|
217 | data = dict(email=email, password=password, |
---|
218 | applicant_id=applicant_id))) |
---|
219 | return |
---|
220 | |
---|
221 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
222 | |
---|
223 | @property |
---|
224 | def payment_slip_download_warning(self): |
---|
225 | return '' |
---|
226 | |
---|
227 | class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage): |
---|
228 | """Captcha'd status checking page for applicants. |
---|
229 | """ |
---|
230 | grok.template('applicantcheckstatus') |
---|