[10765] | 1 | ## $Id: browser.py 16070 2020-04-24 06:59:45Z 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 |
---|
[15878] | 21 | import os |
---|
| 22 | from zope.component import getUtility |
---|
[15807] | 23 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[15878] | 24 | from waeup.kofa.interfaces import ( |
---|
| 25 | IExtFileStore, IFileStoreNameChooser) |
---|
| 26 | from waeup.kofa.utils.helpers import string_from_bytes, file_size, now |
---|
[10765] | 27 | from waeup.kofa.applicants.browser import ( |
---|
[16062] | 28 | ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile, |
---|
| 29 | RefereeReportAddFormPage, ExportPDFReportSlipPage, ExportPDFReportSlipPage2, |
---|
| 30 | RefereeReportDisplayFormPage) |
---|
[15809] | 31 | from waeup.kofa.applicants.interfaces import ( |
---|
[16070] | 32 | ISpecialApplicant, IApplicantsContainer, AppCatCertificateSource) |
---|
[10765] | 33 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 34 | NigeriaApplicantDisplayFormPage, |
---|
[15807] | 35 | NigeriaApplicantManageFormPage, |
---|
| 36 | NigeriaApplicantEditFormPage, |
---|
[10765] | 37 | NigeriaPDFApplicationSlip) |
---|
[15809] | 38 | from waeup.kofa.widgets.datewidget import ( |
---|
| 39 | FriendlyDateDisplayWidget, |
---|
| 40 | FriendlyDatetimeDisplayWidget) |
---|
[15807] | 41 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
[15884] | 42 | OMIT_DISPLAY_FIELDS, |
---|
| 43 | #UG_OMIT_DISPLAY_FIELDS, |
---|
| 44 | #UG_OMIT_PDF_FIELDS, |
---|
| 45 | #UG_OMIT_MANAGE_FIELDS, |
---|
| 46 | #UG_OMIT_EDIT_FIELDS, |
---|
[16049] | 47 | #PG_OMIT_DISPLAY_FIELDS, |
---|
| 48 | #PG_OMIT_PDF_FIELDS, |
---|
| 49 | #PG_OMIT_MANAGE_FIELDS, |
---|
| 50 | #PG_OMIT_EDIT_FIELDS, |
---|
[15807] | 51 | ) |
---|
| 52 | from kofacustom.iuokada.applicants.interfaces import ( |
---|
[15878] | 53 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
[15807] | 54 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
[16062] | 55 | ICustomApplicantOnlinePayment, ICustomApplicantRefereeReport |
---|
[15807] | 56 | ) |
---|
[15563] | 57 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
[10765] | 58 | |
---|
[15878] | 59 | MAX_FILE_UPLOAD_SIZE = 1024 * 500 |
---|
| 60 | |
---|
[15884] | 61 | # UG students are all undergraduate students. |
---|
| 62 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 63 | #'jamb_subjects_list', |
---|
| 64 | 'programme_type',) |
---|
| 65 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
| 66 | UG_OMIT_MANAGE_FIELDS = ( |
---|
| 67 | 'special_application', |
---|
| 68 | #'jamb_subjects_list', |
---|
| 69 | 'programme_type') |
---|
| 70 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
| 71 | 'student_id', |
---|
| 72 | 'notice', |
---|
| 73 | 'screening_score', |
---|
| 74 | 'screening_venue', |
---|
| 75 | 'screening_date', |
---|
| 76 | #'jamb_age', |
---|
| 77 | #'jamb_subjects', |
---|
| 78 | #'jamb_score', |
---|
| 79 | #'jamb_reg_number', |
---|
| 80 | 'aggregate') |
---|
| 81 | |
---|
[16049] | 82 | # PG has its own interface |
---|
[16053] | 83 | PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 84 | 'employer', |
---|
| 85 | 'emp_position', |
---|
| 86 | 'emp_start', |
---|
| 87 | 'emp_end', |
---|
| 88 | 'emp_reason', |
---|
| 89 | 'employer2', |
---|
| 90 | 'emp2_position', |
---|
| 91 | 'emp2_start', |
---|
| 92 | 'emp2_end', |
---|
| 93 | 'emp2_reason', |
---|
| 94 | ) |
---|
[16049] | 95 | PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
| 96 | PG_OMIT_MANAGE_FIELDS = ( |
---|
| 97 | 'special_application', |
---|
| 98 | 'employer', |
---|
| 99 | 'emp_position', |
---|
| 100 | 'emp_start', |
---|
| 101 | 'emp_end', |
---|
| 102 | 'emp_reason', |
---|
| 103 | 'employer2', |
---|
| 104 | 'emp2_position', |
---|
| 105 | 'emp2_start', |
---|
| 106 | 'emp2_end', |
---|
| 107 | 'emp2_reason', |
---|
| 108 | ) |
---|
| 109 | PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + ( |
---|
[16053] | 110 | 'student_id', |
---|
| 111 | 'notice', |
---|
| 112 | 'screening_score', |
---|
| 113 | 'screening_venue', |
---|
[16049] | 114 | 'screening_date',) |
---|
| 115 | |
---|
[15809] | 116 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
| 117 | """The standard view for regular applicant containers. |
---|
| 118 | """ |
---|
| 119 | |
---|
| 120 | @property |
---|
| 121 | def form_fields(self): |
---|
| 122 | form_fields = grok.AutoFields(IApplicantsContainer).omit( |
---|
| 123 | 'title', 'description') |
---|
| 124 | if self.request.principal.id == 'zope.anybody': |
---|
| 125 | form_fields = form_fields.omit( |
---|
| 126 | 'code', 'prefix', 'year', 'mode', 'hidden', |
---|
| 127 | 'strict_deadline', 'application_category', |
---|
[15883] | 128 | 'application_slip_notice', |
---|
| 129 | 'application_fee', 'with_picture', |
---|
| 130 | 'startdate', 'enddate') |
---|
[15809] | 131 | return form_fields |
---|
| 132 | |
---|
[15793] | 133 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 134 | """A display view for applicant data. |
---|
| 135 | """ |
---|
[15807] | 136 | |
---|
[15793] | 137 | @property |
---|
| 138 | def form_fields(self): |
---|
[15807] | 139 | if self.target is not None and self.target.startswith('pg'): |
---|
| 140 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 141 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 142 | form_fields = form_fields.omit(field) |
---|
[15793] | 143 | else: |
---|
[15807] | 144 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 145 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 146 | form_fields = form_fields.omit(field) |
---|
| 147 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 148 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 149 | if not getattr(self.context, 'student_id'): |
---|
| 150 | form_fields = form_fields.omit('student_id') |
---|
| 151 | if not getattr(self.context, 'screening_score'): |
---|
| 152 | form_fields = form_fields.omit('screening_score') |
---|
| 153 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
| 154 | form_fields = form_fields.omit('screening_venue') |
---|
| 155 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
| 156 | form_fields = form_fields.omit('screening_date') |
---|
[15793] | 157 | return form_fields |
---|
| 158 | |
---|
[15807] | 159 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 160 | """A full edit view for applicant data. |
---|
| 161 | """ |
---|
| 162 | |
---|
| 163 | @property |
---|
[16070] | 164 | def certs(self): |
---|
| 165 | appcatcertificatesource = AppCatCertificateSource().factory |
---|
| 166 | for code in appcatcertificatesource.getValues(self.context): |
---|
| 167 | title = appcatcertificatesource.getTitle(self.context, code) |
---|
| 168 | yield(code, title) |
---|
| 169 | |
---|
| 170 | @property |
---|
[16051] | 171 | def display_refereereports(self): |
---|
| 172 | if self.context.refereereports: |
---|
| 173 | return True |
---|
| 174 | return False |
---|
| 175 | |
---|
| 176 | @property |
---|
[15807] | 177 | def form_fields(self): |
---|
| 178 | if self.target is not None and self.target.startswith('pg'): |
---|
| 179 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 180 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 181 | form_fields = form_fields.omit(field) |
---|
| 182 | else: |
---|
| 183 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 184 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 185 | form_fields = form_fields.omit(field) |
---|
| 186 | form_fields['student_id'].for_display = True |
---|
| 187 | form_fields['applicant_id'].for_display = True |
---|
| 188 | return form_fields |
---|
| 189 | |
---|
| 190 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
| 191 | """An applicant-centered edit view for applicant data. |
---|
| 192 | """ |
---|
| 193 | |
---|
[16070] | 194 | grok.template('applicanteditpage') |
---|
| 195 | |
---|
[15947] | 196 | def display_fileupload(self, filename): |
---|
| 197 | if filename[1] == 'res_stat.pdf': |
---|
| 198 | if self.context.subtype != 'transfer': |
---|
| 199 | return False |
---|
[16051] | 200 | if filename[1] == 'jamb.pdf' \ |
---|
| 201 | and self.target is not None \ |
---|
| 202 | and self.target.startswith('pg'): |
---|
| 203 | return False |
---|
[16052] | 204 | if filename[1] == 'nysc.pdf' \ |
---|
| 205 | and self.target is not None \ |
---|
| 206 | and not self.target.startswith('pg'): |
---|
| 207 | return False |
---|
[15947] | 208 | return True |
---|
| 209 | |
---|
[15878] | 210 | def dataNotComplete(self, data): |
---|
| 211 | store = getUtility(IExtFileStore) |
---|
| 212 | if self.context.__parent__.with_picture: |
---|
| 213 | store = getUtility(IExtFileStore) |
---|
| 214 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 215 | return _('No passport picture uploaded.') |
---|
| 216 | if not self.request.form.get('confirm_passport', False): |
---|
| 217 | return _('Passport picture confirmation box not ticked.') |
---|
| 218 | if self.context.subtype == 'transfer' and \ |
---|
[15942] | 219 | not store.getFileByContext(self.context, attr=u'res_stat.pdf'): |
---|
[15878] | 220 | return _('No statement of result pdf file uploaded.') |
---|
| 221 | return False |
---|
| 222 | |
---|
[15807] | 223 | @property |
---|
| 224 | def form_fields(self): |
---|
| 225 | if self.target is not None and self.target.startswith('pg'): |
---|
| 226 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
| 227 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 228 | form_fields = form_fields.omit(field) |
---|
| 229 | else: |
---|
| 230 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 231 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 232 | form_fields = form_fields.omit(field) |
---|
| 233 | form_fields['applicant_id'].for_display = True |
---|
| 234 | form_fields['reg_number'].for_display = True |
---|
| 235 | return form_fields |
---|
| 236 | |
---|
| 237 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 238 | |
---|
| 239 | @property |
---|
| 240 | def form_fields(self): |
---|
| 241 | if self.target is not None and self.target.startswith('pg'): |
---|
| 242 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 243 | for field in PG_OMIT_PDF_FIELDS: |
---|
| 244 | form_fields = form_fields.omit(field) |
---|
| 245 | else: |
---|
| 246 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 247 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 248 | form_fields = form_fields.omit(field) |
---|
| 249 | if not getattr(self.context, 'student_id'): |
---|
| 250 | form_fields = form_fields.omit('student_id') |
---|
| 251 | if not getattr(self.context, 'screening_score'): |
---|
| 252 | form_fields = form_fields.omit('screening_score') |
---|
| 253 | if not getattr(self.context, 'screening_venue'): |
---|
| 254 | form_fields = form_fields.omit('screening_venue') |
---|
| 255 | if not getattr(self.context, 'screening_date'): |
---|
| 256 | form_fields = form_fields.omit('screening_date') |
---|
| 257 | return form_fields |
---|
| 258 | |
---|
[16062] | 259 | class RefereeReportAddFormPage(RefereeReportAddFormPage): |
---|
| 260 | """Add-form to add an referee report. This form |
---|
| 261 | is protected by a mandate. |
---|
| 262 | """ |
---|
| 263 | form_fields = grok.AutoFields( |
---|
| 264 | ICustomApplicantRefereeReport).omit('creation_date') |
---|
| 265 | |
---|
| 266 | class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage): |
---|
| 267 | """A display view for referee reports. |
---|
| 268 | """ |
---|
| 269 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
| 270 | form_fields[ |
---|
| 271 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage): |
---|
| 275 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
| 276 | form_fields[ |
---|
| 277 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 278 | |
---|
| 279 | class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2): |
---|
| 280 | form_fields = grok.AutoFields(ICustomApplicantRefereeReport) |
---|
| 281 | form_fields[ |
---|
| 282 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 283 | |
---|
[15947] | 284 | class ResultStatement(AdditionalFile): |
---|
[15942] | 285 | grok.name('res_stat.pdf') |
---|
[15878] | 286 | |
---|
[15947] | 287 | class JAMBResult(AdditionalFile): |
---|
| 288 | grok.name('jamb.pdf') |
---|
[16014] | 289 | |
---|
| 290 | class FirstSitting(AdditionalFile): |
---|
| 291 | grok.name('fst_sit_scan.pdf') |
---|
| 292 | |
---|
| 293 | class SecondSitting(AdditionalFile): |
---|
| 294 | grok.name('scd_sit_scan.pdf') |
---|
| 295 | |
---|
| 296 | class HighQual(AdditionalFile): |
---|
| 297 | grok.name('hq_scan.pdf') |
---|
[16017] | 298 | |
---|
| 299 | class AdvancedLevelResult(AdditionalFile): |
---|
| 300 | grok.name('alr_scan.pdf') |
---|
[16052] | 301 | |
---|
| 302 | class NYSCCertificate(AdditionalFile): |
---|
| 303 | grok.name('nysc.pdf') |
---|