[10298] | 1 | ## $Id: browser.py 13977 2016-06-23 07:25:56Z 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 |
---|
[13422] | 27 | from waeup.kofa.applicants.browser import ApplicantCheckStatusPage |
---|
[13538] | 28 | from waeup.kofa.applicants.viewlets import PDFActionButton |
---|
[10298] | 29 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
| 30 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 31 | NigeriaApplicantDisplayFormPage, |
---|
| 32 | NigeriaApplicantManageFormPage, |
---|
| 33 | NigeriaApplicantEditFormPage, |
---|
| 34 | NigeriaPDFApplicationSlip, |
---|
[10929] | 35 | NigeriaApplicantRegistrationPage, |
---|
[11755] | 36 | NigeriaExportPDFPaymentSlipPage, |
---|
[13545] | 37 | ) |
---|
| 38 | from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS |
---|
[10298] | 39 | from waeup.aaue.applicants.interfaces import ( |
---|
| 40 | ICustomUGApplicant, |
---|
[13544] | 41 | ICustomUGApplicantEdit, |
---|
| 42 | ITranscriptApplicant |
---|
[11291] | 43 | ) |
---|
[10298] | 44 | |
---|
[13545] | 45 | UG_OMIT_FIELDS = ( |
---|
| 46 | 'hq_type', 'hq_fname', 'hq_matric_no', |
---|
| 47 | 'hq_degree', 'hq_school', 'hq_session', 'hq_disc', |
---|
| 48 | 'hq_type2', 'hq_fname2', 'hq_matric_no2', |
---|
| 49 | 'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2', |
---|
| 50 | 'hq_type3', 'hq_fname3', 'hq_matric_no3', |
---|
[13679] | 51 | 'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3', |
---|
| 52 | 'nysc_year', |
---|
| 53 | 'nysc_location', |
---|
| 54 | 'nysc_lga', |
---|
| 55 | 'employer', |
---|
| 56 | 'emp_position', |
---|
| 57 | 'emp_start', |
---|
| 58 | 'emp_end', |
---|
| 59 | 'emp_reason', |
---|
| 60 | 'employer2', |
---|
| 61 | 'emp2_position', |
---|
| 62 | 'emp2_start', |
---|
| 63 | 'emp2_end', |
---|
| 64 | 'emp2_reason', |
---|
| 65 | 'former_matric', |
---|
[13545] | 66 | ) |
---|
[13546] | 67 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
[13977] | 68 | 'jamb_subjects_list', 'master_sheet_number') + UG_OMIT_FIELDS |
---|
[13545] | 69 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + ( |
---|
| 70 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
| 71 | 'alr_results', 'notice') |
---|
[13546] | 72 | UG_OMIT_MANAGE_FIELDS = ( |
---|
| 73 | 'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS |
---|
| 74 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
[13545] | 75 | 'student_id', |
---|
| 76 | 'notice', |
---|
| 77 | 'jamb_age', |
---|
| 78 | 'jamb_subjects', |
---|
| 79 | 'jamb_score', |
---|
| 80 | 'jamb_reg_number', |
---|
[13679] | 81 | 'aggregate', |
---|
[13977] | 82 | |
---|
| 83 | 'firstname', |
---|
| 84 | 'middlename', |
---|
| 85 | 'lastname', |
---|
| 86 | 'sex', |
---|
| 87 | 'lga', |
---|
| 88 | 'course1', |
---|
| 89 | 'master_sheet_number', |
---|
[13679] | 90 | ) |
---|
[10298] | 91 | |
---|
[13545] | 92 | #UG_OMIT_PDF_FIELDS = tuple([ |
---|
| 93 | # element for element in UG_OMIT_PDF_FIELDS if not element == 'phone']) |
---|
[11291] | 94 | |
---|
[13545] | 95 | #UG_OMIT_PDF_FIELDS += ( |
---|
| 96 | # 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
| 97 | # 'alr_results', 'notice' |
---|
| 98 | # ) |
---|
[13538] | 99 | |
---|
[13545] | 100 | PG_OMIT_FIELDS = ( |
---|
| 101 | 'fst_sit_fname', |
---|
| 102 | 'fst_sit_no', |
---|
| 103 | 'fst_sit_date', |
---|
| 104 | 'fst_sit_type', |
---|
| 105 | 'fst_sit_results', |
---|
| 106 | 'scd_sit_fname', |
---|
| 107 | 'scd_sit_no', |
---|
| 108 | 'scd_sit_date', |
---|
| 109 | 'scd_sit_type', |
---|
| 110 | 'scd_sit_results', |
---|
[13977] | 111 | #'programme_type', |
---|
[13546] | 112 | 'jamb_age', |
---|
| 113 | 'jamb_subjects', |
---|
| 114 | 'jamb_score', |
---|
| 115 | 'jamb_reg_number', |
---|
| 116 | 'aggregate' |
---|
[13545] | 117 | ) |
---|
| 118 | PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 119 | 'jamb_subjects_list',) + PG_OMIT_FIELDS |
---|
| 120 | PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + ( |
---|
| 121 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
[13679] | 122 | 'alr_results', 'notice', |
---|
| 123 | 'nysc_year', |
---|
| 124 | 'nysc_location', |
---|
| 125 | 'nysc_lga', |
---|
| 126 | 'former_matric', |
---|
| 127 | ) |
---|
[13545] | 128 | PG_OMIT_MANAGE_FIELDS = ( |
---|
| 129 | 'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS |
---|
[13546] | 130 | PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
[13545] | 131 | 'student_id', |
---|
| 132 | 'notice', |
---|
[13546] | 133 | ) |
---|
[13545] | 134 | |
---|
[13679] | 135 | PTEE_OMIT_FIELDS = ( |
---|
| 136 | 'jamb_age', |
---|
| 137 | 'jamb_subjects', |
---|
| 138 | 'jamb_score', |
---|
| 139 | 'jamb_reg_number', |
---|
| 140 | 'aggregate' |
---|
| 141 | ) |
---|
| 142 | PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 143 | 'jamb_subjects_list',) + PTEE_OMIT_FIELDS |
---|
| 144 | PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + ( |
---|
| 145 | 'reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
| 146 | 'alr_results', 'notice', |
---|
| 147 | 'nysc_year', |
---|
| 148 | 'nysc_location', |
---|
| 149 | 'nysc_lga', |
---|
| 150 | 'employer', |
---|
| 151 | 'emp_position', |
---|
| 152 | 'emp_start', |
---|
| 153 | 'emp_end', |
---|
| 154 | 'emp_reason', |
---|
| 155 | 'employer2', |
---|
| 156 | 'emp2_position', |
---|
| 157 | 'emp2_start', |
---|
| 158 | 'emp2_end', |
---|
| 159 | 'emp2_reason', |
---|
| 160 | 'former_matric', |
---|
| 161 | ) |
---|
| 162 | PTEE_OMIT_MANAGE_FIELDS = ( |
---|
| 163 | 'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS |
---|
| 164 | PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
| 165 | 'student_id', |
---|
| 166 | 'notice', |
---|
| 167 | ) |
---|
| 168 | |
---|
[10298] | 169 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 170 | """A display view for applicant data. |
---|
| 171 | """ |
---|
| 172 | |
---|
| 173 | @property |
---|
| 174 | def form_fields(self): |
---|
[13538] | 175 | if self.target is not None and self.target == 'trans': |
---|
[13544] | 176 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
| 177 | 'locked', 'suspended') |
---|
| 178 | form_fields['dispatch_address'].custom_widget = BytesDisplayWidget |
---|
| 179 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 180 | return form_fields |
---|
[13538] | 181 | # AAUE is using the same interface for all regular applications. |
---|
[11291] | 182 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
[13538] | 183 | if self.target is not None and self.target.startswith('pg'): |
---|
| 184 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 185 | form_fields = form_fields.omit(field) |
---|
[13967] | 186 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
[13679] | 187 | for field in PTEE_OMIT_DISPLAY_FIELDS: |
---|
[10298] | 188 | form_fields = form_fields.omit(field) |
---|
| 189 | else: |
---|
| 190 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 191 | form_fields = form_fields.omit(field) |
---|
| 192 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 193 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 194 | if not getattr(self.context, 'student_id'): |
---|
| 195 | form_fields = form_fields.omit('student_id') |
---|
| 196 | if not getattr(self.context, 'screening_score'): |
---|
| 197 | form_fields = form_fields.omit('screening_score') |
---|
| 198 | if not getattr(self.context, 'screening_venue'): |
---|
| 199 | form_fields = form_fields.omit('screening_venue') |
---|
| 200 | if not getattr(self.context, 'screening_date'): |
---|
| 201 | form_fields = form_fields.omit('screening_date') |
---|
| 202 | return form_fields |
---|
| 203 | |
---|
[13538] | 204 | class CustomPDFActionButton(PDFActionButton): |
---|
| 205 | |
---|
| 206 | @property |
---|
| 207 | def target_url(self): |
---|
[13540] | 208 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
[13541] | 209 | or self.context.special or self.view.target == 'trans': |
---|
[13540] | 210 | return |
---|
| 211 | return self.view.url(self.view.context, self.target) |
---|
[13538] | 212 | |
---|
| 213 | |
---|
[10298] | 214 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 215 | |
---|
[10311] | 216 | column_two_fields = ('applicant_id', 'reg_number', |
---|
| 217 | 'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth') |
---|
[13679] | 218 | #two_columns_design_fields = [ |
---|
| 219 | # 'fst_sit_fname', 'fst_sit_no', 'fst_sit_date', |
---|
| 220 | # 'fst_sit_type', 'fst_sit_results', |
---|
| 221 | # 'scd_sit_fname', 'scd_sit_no', 'scd_sit_date', |
---|
| 222 | # 'scd_sit_type', 'scd_sit_results'] |
---|
[10311] | 223 | |
---|
[10301] | 224 | @property |
---|
| 225 | def note(self): |
---|
| 226 | if self.context.sex == 'm': |
---|
| 227 | pronoun = 'he' |
---|
| 228 | else: |
---|
| 229 | pronoun = 'she' |
---|
| 230 | return ''' |
---|
[10897] | 231 | The applicant has acknowledged that, if discovered at any time that %s does not possess |
---|
| 232 | any of the qualifications which %s claims %s has obtained, %s will be expelled from the |
---|
| 233 | University not be re-admitted for the same or any other programme, even if %s has |
---|
| 234 | upgraded previous and shall qualifications or possess additional qualifications. |
---|
[10331] | 235 | ''' % ( |
---|
[10301] | 236 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
[10298] | 237 | |
---|
| 238 | @property |
---|
| 239 | def form_fields(self): |
---|
[13538] | 240 | # AAUE is using the same interface for all regular applications. |
---|
[11291] | 241 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
[13538] | 242 | if self.target is not None and self.target.startswith('pg'): |
---|
| 243 | for field in PG_OMIT_PDF_FIELDS: |
---|
| 244 | form_fields = form_fields.omit(field) |
---|
[13967] | 245 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
[13679] | 246 | for field in PTEE_OMIT_PDF_FIELDS: |
---|
[10298] | 247 | form_fields = form_fields.omit(field) |
---|
| 248 | else: |
---|
| 249 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 250 | form_fields = form_fields.omit(field) |
---|
| 251 | if not getattr(self.context, 'student_id'): |
---|
| 252 | form_fields = form_fields.omit('student_id') |
---|
| 253 | if not getattr(self.context, 'screening_score'): |
---|
| 254 | form_fields = form_fields.omit('screening_score') |
---|
| 255 | if not getattr(self.context, 'screening_venue'): |
---|
| 256 | form_fields = form_fields.omit('screening_venue') |
---|
| 257 | if not getattr(self.context, 'screening_date'): |
---|
| 258 | form_fields = form_fields.omit('screening_date') |
---|
| 259 | return form_fields |
---|
| 260 | |
---|
| 261 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 262 | """A full edit view for applicant data. |
---|
| 263 | """ |
---|
| 264 | |
---|
| 265 | @property |
---|
| 266 | def form_fields(self): |
---|
[13538] | 267 | if self.target is not None and self.target == 'trans': |
---|
[13544] | 268 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
[13538] | 269 | form_fields['applicant_id'].for_display = True |
---|
| 270 | return form_fields |
---|
| 271 | # AAUE is using the same interface for all regular applications. |
---|
[11291] | 272 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
[13538] | 273 | if self.target is not None and self.target.startswith('pg'): |
---|
| 274 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 275 | form_fields = form_fields.omit(field) |
---|
[13967] | 276 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
[13679] | 277 | for field in PTEE_OMIT_MANAGE_FIELDS: |
---|
[10298] | 278 | form_fields = form_fields.omit(field) |
---|
| 279 | else: |
---|
| 280 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 281 | form_fields = form_fields.omit(field) |
---|
| 282 | form_fields['student_id'].for_display = True |
---|
| 283 | form_fields['applicant_id'].for_display = True |
---|
| 284 | return form_fields |
---|
| 285 | |
---|
| 286 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
| 287 | """An applicant-centered edit view for applicant data. |
---|
| 288 | """ |
---|
| 289 | |
---|
[13547] | 290 | grok.template('applicanteditpage') |
---|
[13541] | 291 | |
---|
[10298] | 292 | @property |
---|
| 293 | def form_fields(self): |
---|
[13538] | 294 | if self.target is not None and self.target == 'trans': |
---|
[13544] | 295 | form_fields = grok.AutoFields(ITranscriptApplicant).omit( |
---|
| 296 | 'locked', 'suspended') |
---|
[13538] | 297 | form_fields['applicant_id'].for_display = True |
---|
| 298 | return form_fields |
---|
| 299 | # AAUE is using the same interface for all regular applications. |
---|
[11291] | 300 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
[13538] | 301 | if self.target is not None and self.target.startswith('pg'): |
---|
| 302 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 303 | form_fields = form_fields.omit(field) |
---|
[13967] | 304 | elif self.target is not None and self.target in ('ptee', 'ude'): |
---|
[13679] | 305 | for field in PTEE_OMIT_EDIT_FIELDS: |
---|
[10298] | 306 | form_fields = form_fields.omit(field) |
---|
| 307 | else: |
---|
| 308 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 309 | form_fields = form_fields.omit(field) |
---|
| 310 | form_fields['applicant_id'].for_display = True |
---|
| 311 | form_fields['reg_number'].for_display = True |
---|
| 312 | return form_fields |
---|
[10929] | 313 | |
---|
| 314 | class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage): |
---|
| 315 | """Captcha'd registration page for applicants. |
---|
| 316 | """ |
---|
| 317 | |
---|
| 318 | def _redirect(self, email, password, applicant_id): |
---|
| 319 | # Forward email and credentials to landing page. |
---|
| 320 | self.redirect(self.url(self.context, 'registration_complete', |
---|
| 321 | data = dict(email=email, password=password, |
---|
| 322 | applicant_id=applicant_id))) |
---|
[11755] | 323 | return |
---|
| 324 | |
---|
| 325 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
| 326 | |
---|
| 327 | @property |
---|
| 328 | def payment_slip_download_warning(self): |
---|
[13422] | 329 | return '' |
---|
| 330 | |
---|
| 331 | class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage): |
---|
| 332 | """Captcha'd status checking page for applicants. |
---|
| 333 | """ |
---|
| 334 | grok.template('applicantcheckstatus') |
---|