[10765] | 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 |
---|
[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 ( |
---|
[15947] | 28 | ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile) |
---|
[15809] | 29 | from waeup.kofa.applicants.interfaces import ( |
---|
| 30 | ISpecialApplicant, IApplicantsContainer) |
---|
[10765] | 31 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 32 | NigeriaApplicantDisplayFormPage, |
---|
[15807] | 33 | NigeriaApplicantManageFormPage, |
---|
| 34 | NigeriaApplicantEditFormPage, |
---|
[10765] | 35 | NigeriaPDFApplicationSlip) |
---|
[15809] | 36 | from waeup.kofa.widgets.datewidget import ( |
---|
| 37 | FriendlyDateDisplayWidget, |
---|
| 38 | FriendlyDatetimeDisplayWidget) |
---|
[15807] | 39 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
[15884] | 40 | OMIT_DISPLAY_FIELDS, |
---|
| 41 | #UG_OMIT_DISPLAY_FIELDS, |
---|
| 42 | #UG_OMIT_PDF_FIELDS, |
---|
| 43 | #UG_OMIT_MANAGE_FIELDS, |
---|
| 44 | #UG_OMIT_EDIT_FIELDS, |
---|
[15807] | 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 ( |
---|
[15878] | 51 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
[15807] | 52 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
| 53 | ICustomApplicantOnlinePayment |
---|
| 54 | ) |
---|
[15563] | 55 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
[10765] | 56 | |
---|
[15878] | 57 | MAX_FILE_UPLOAD_SIZE = 1024 * 500 |
---|
| 58 | |
---|
[15884] | 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 | |
---|
[15809] | 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', |
---|
[15883] | 92 | 'application_slip_notice', |
---|
| 93 | 'application_fee', 'with_picture', |
---|
| 94 | 'startdate', 'enddate') |
---|
[15809] | 95 | return form_fields |
---|
| 96 | |
---|
[15793] | 97 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 98 | """A display view for applicant data. |
---|
| 99 | """ |
---|
[15807] | 100 | |
---|
[15793] | 101 | @property |
---|
| 102 | def form_fields(self): |
---|
[15807] | 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) |
---|
[15793] | 107 | else: |
---|
[15807] | 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') |
---|
[15793] | 121 | return form_fields |
---|
| 122 | |
---|
[15807] | 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 | |
---|
[15947] | 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 | |
---|
[15878] | 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 \ |
---|
[15942] | 160 | not store.getFileByContext(self.context, attr=u'res_stat.pdf'): |
---|
[15878] | 161 | return _('No statement of result pdf file uploaded.') |
---|
| 162 | return False |
---|
| 163 | |
---|
[15807] | 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 | |
---|
[15947] | 200 | class ResultStatement(AdditionalFile): |
---|
[15878] | 201 | """Renders the pdf form extension for applicants. |
---|
| 202 | """ |
---|
[15942] | 203 | grok.name('res_stat.pdf') |
---|
[15878] | 204 | |
---|
[15947] | 205 | class JAMBResult(AdditionalFile): |
---|
| 206 | """Renders the pdf form extension for applicants. |
---|
| 207 | """ |
---|
| 208 | grok.name('jamb.pdf') |
---|