[16639] | 1 | ## $Id: browser.py 17169 2022-11-23 14:25:22Z henrik $ |
---|
[15614] | 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 |
---|
[16618] | 21 | from zope.component import getUtility |
---|
| 22 | from zope.i18n import translate |
---|
[17041] | 23 | from waeup.kofa.interfaces import IExtFileStore, IKofaUtils |
---|
[16618] | 24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
| 25 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
| 26 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
| 27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
| 28 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
| 29 | ApplicantRegistrationPage, |
---|
| 30 | OnlinePaymentDisplayFormPage, |
---|
| 31 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
[17041] | 32 | AdditionalFile |
---|
[16618] | 33 | ) |
---|
| 34 | from waeup.kofa.applicants.viewlets import ( |
---|
| 35 | PDFActionButton, PaymentReceiptActionButton) |
---|
| 36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
[15614] | 37 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 38 | NigeriaApplicantDisplayFormPage, |
---|
[16618] | 39 | NigeriaApplicantManageFormPage, |
---|
| 40 | NigeriaApplicantEditFormPage, |
---|
[15614] | 41 | NigeriaPDFApplicationSlip) |
---|
[16618] | 42 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 43 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
| 44 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
| 45 | INigeriaApplicantOnlinePayment, |
---|
[16643] | 46 | #UG_OMIT_DISPLAY_FIELDS, |
---|
| 47 | #UG_OMIT_PDF_FIELDS, |
---|
| 48 | #UG_OMIT_MANAGE_FIELDS, |
---|
| 49 | #UG_OMIT_EDIT_FIELDS, |
---|
[16618] | 50 | PG_OMIT_DISPLAY_FIELDS, |
---|
| 51 | PG_OMIT_PDF_FIELDS, |
---|
| 52 | PG_OMIT_MANAGE_FIELDS, |
---|
| 53 | PG_OMIT_EDIT_FIELDS, |
---|
| 54 | ) |
---|
| 55 | from kofacustom.edocons.applicants.interfaces import ( |
---|
| 56 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
| 57 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
[17029] | 58 | ICustomApplicantOnlinePayment, ITranscriptApplicant, |
---|
[16618] | 59 | ) |
---|
| 60 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
[15614] | 61 | |
---|
[16643] | 62 | # Fields to be omitted in all display forms. course_admitted is |
---|
| 63 | # rendered separately. |
---|
| 64 | |
---|
| 65 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
| 66 | 'result_uploaded', 'suspended', 'special_application', |
---|
| 67 | 'bank_account_number', |
---|
| 68 | 'bank_account_name', |
---|
| 69 | 'bank_name', |
---|
[16853] | 70 | #'course1', 'course2' # these 2 have been added and later removed again |
---|
| 71 | ) |
---|
[16643] | 72 | |
---|
| 73 | # UG students are all undergraduate students. |
---|
| 74 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 75 | 'jamb_subjects_list', 'programme_type') |
---|
| 76 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
| 77 | UG_OMIT_MANAGE_FIELDS = ( |
---|
| 78 | 'special_application', |
---|
| 79 | 'jamb_subjects_list', |
---|
[16655] | 80 | 'programme_type', |
---|
[16852] | 81 | #'course1', 'course2', # these 2 have been added and later removed again |
---|
| 82 | ) |
---|
[16643] | 83 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
| 84 | 'student_id', |
---|
| 85 | 'notice', |
---|
| 86 | 'screening_score', |
---|
| 87 | 'screening_venue', |
---|
| 88 | 'screening_date', |
---|
[16769] | 89 | 'cbt_score', |
---|
| 90 | 'cbt_venue', |
---|
| 91 | 'cbt_date', |
---|
[16643] | 92 | 'jamb_age', |
---|
| 93 | 'jamb_subjects', |
---|
| 94 | 'jamb_score', |
---|
| 95 | 'jamb_reg_number', |
---|
| 96 | 'aggregate') |
---|
| 97 | |
---|
[17029] | 98 | TSC_OMIT_FIELDS = ('locked', 'suspended', |
---|
| 99 | ) |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | TSC_OMIT_EDIT_FIELDS = TSC_OMIT_FIELDS + ( |
---|
| 103 | 'applicant_id', |
---|
| 104 | 'proc_date', |
---|
[17039] | 105 | 'courier_tno', |
---|
[17029] | 106 | ) |
---|
| 107 | |
---|
| 108 | TSC_OMIT_MANAGE_FIELDS = TSC_OMIT_FIELDS + ( |
---|
| 109 | 'applicant_id',) |
---|
| 110 | |
---|
[16618] | 111 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 112 | """A display view for applicant data. |
---|
| 113 | """ |
---|
[15614] | 114 | |
---|
[16618] | 115 | @property |
---|
| 116 | def form_fields(self): |
---|
| 117 | if self.target is not None and self.target.startswith('pg'): |
---|
| 118 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 119 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 120 | form_fields = form_fields.omit(field) |
---|
[17029] | 121 | elif self.target is not None and self.target.startswith('tsc'): |
---|
| 122 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
| 123 | for field in TSC_OMIT_FIELDS: |
---|
| 124 | form_fields = form_fields.omit(field) |
---|
| 125 | return form_fields |
---|
[16618] | 126 | else: |
---|
| 127 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 128 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 129 | form_fields = form_fields.omit(field) |
---|
[17029] | 130 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
[16618] | 131 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 132 | if not getattr(self.context, 'student_id'): |
---|
| 133 | form_fields = form_fields.omit('student_id') |
---|
| 134 | if not getattr(self.context, 'screening_score'): |
---|
| 135 | form_fields = form_fields.omit('screening_score') |
---|
| 136 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
| 137 | form_fields = form_fields.omit('screening_venue') |
---|
| 138 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
| 139 | form_fields = form_fields.omit('screening_date') |
---|
[16769] | 140 | if not getattr(self.context, 'cbt_score'): |
---|
| 141 | form_fields = form_fields.omit('cbt_score') |
---|
| 142 | if not getattr(self.context, 'cbt_venue') or self._not_paid(): |
---|
| 143 | form_fields = form_fields.omit('cbt_venue') |
---|
| 144 | if not getattr(self.context, 'cbt_date') or self._not_paid(): |
---|
| 145 | form_fields = form_fields.omit('cbt_date') |
---|
[16618] | 146 | return form_fields |
---|
| 147 | |
---|
| 148 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 149 | |
---|
| 150 | @property |
---|
| 151 | def form_fields(self): |
---|
| 152 | if self.target is not None and self.target.startswith('pg'): |
---|
| 153 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 154 | for field in PG_OMIT_PDF_FIELDS: |
---|
| 155 | form_fields = form_fields.omit(field) |
---|
[17029] | 156 | elif self.target is not None and self.target.startswith('tsc'): |
---|
| 157 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
| 158 | for field in TSC_OMIT_FIELDS: |
---|
| 159 | form_fields = form_fields.omit(field) |
---|
| 160 | return form_fields |
---|
[16618] | 161 | else: |
---|
| 162 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 163 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 164 | form_fields = form_fields.omit(field) |
---|
| 165 | if not getattr(self.context, 'student_id'): |
---|
| 166 | form_fields = form_fields.omit('student_id') |
---|
| 167 | if not getattr(self.context, 'screening_score'): |
---|
| 168 | form_fields = form_fields.omit('screening_score') |
---|
| 169 | if not getattr(self.context, 'screening_venue'): |
---|
| 170 | form_fields = form_fields.omit('screening_venue') |
---|
| 171 | if not getattr(self.context, 'screening_date'): |
---|
| 172 | form_fields = form_fields.omit('screening_date') |
---|
[16769] | 173 | if not getattr(self.context, 'cbt_score'): |
---|
| 174 | form_fields = form_fields.omit('cbt_score') |
---|
| 175 | if not getattr(self.context, 'cbt_venue'): |
---|
| 176 | form_fields = form_fields.omit('cbt_venue') |
---|
| 177 | if not getattr(self.context, 'cbt_date'): |
---|
| 178 | form_fields = form_fields.omit('cbt_date') |
---|
[16618] | 179 | return form_fields |
---|
| 180 | |
---|
| 181 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 182 | """A full edit view for applicant data. |
---|
| 183 | """ |
---|
| 184 | |
---|
[17041] | 185 | def display_fileupload(self, filename): |
---|
[17106] | 186 | if self.target is not None and not self.target.startswith('tsc'): |
---|
[17041] | 187 | return False |
---|
[17169] | 188 | return True |
---|
[17041] | 189 | |
---|
[16618] | 190 | @property |
---|
| 191 | def form_fields(self): |
---|
| 192 | if self.target is not None and self.target.startswith('pg'): |
---|
| 193 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 194 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 195 | form_fields = form_fields.omit(field) |
---|
[17029] | 196 | elif self.target is not None and self.target.startswith('tsc'): |
---|
| 197 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
| 198 | for field in TSC_OMIT_MANAGE_FIELDS: |
---|
| 199 | form_fields = form_fields.omit(field) |
---|
| 200 | return form_fields |
---|
[16618] | 201 | else: |
---|
| 202 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 203 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 204 | form_fields = form_fields.omit(field) |
---|
| 205 | form_fields['student_id'].for_display = True |
---|
| 206 | form_fields['applicant_id'].for_display = True |
---|
| 207 | return form_fields |
---|
| 208 | |
---|
| 209 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
| 210 | """An applicant-centered edit view for applicant data. |
---|
| 211 | """ |
---|
| 212 | |
---|
[16664] | 213 | def unremovable(self, ticket): |
---|
| 214 | return True |
---|
| 215 | |
---|
[17041] | 216 | def display_fileupload(self, filename): |
---|
[17106] | 217 | if self.target is not None and not self.target.startswith('tsc'): |
---|
[17041] | 218 | return False |
---|
[17169] | 219 | return True |
---|
[17041] | 220 | |
---|
[16618] | 221 | @property |
---|
| 222 | def form_fields(self): |
---|
| 223 | if self.target is not None and self.target.startswith('pg'): |
---|
| 224 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
| 225 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 226 | form_fields = form_fields.omit(field) |
---|
[17029] | 227 | elif self.target is not None and self.target.startswith('tsc'): |
---|
| 228 | form_fields = grok.AutoFields(ITranscriptApplicant) |
---|
| 229 | for field in TSC_OMIT_EDIT_FIELDS: |
---|
| 230 | form_fields = form_fields.omit(field) |
---|
| 231 | return form_fields |
---|
[16618] | 232 | else: |
---|
| 233 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 234 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 235 | form_fields = form_fields.omit(field) |
---|
| 236 | form_fields['applicant_id'].for_display = True |
---|
| 237 | form_fields['reg_number'].for_display = True |
---|
[17041] | 238 | return form_fields |
---|
| 239 | |
---|
| 240 | def dataNotComplete(self, data): |
---|
| 241 | store = getUtility(IExtFileStore) |
---|
| 242 | if self.context.__parent__.with_picture \ |
---|
| 243 | and self.context.__parent__.picture_editable: |
---|
| 244 | store = getUtility(IExtFileStore) |
---|
| 245 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 246 | return _('No passport picture uploaded.') |
---|
| 247 | if self.target is not None \ |
---|
| 248 | and self.target.startswith('tscf') \ |
---|
| 249 | and not store.getFileByContext(self.context, attr=u'res_stat.pdf'): |
---|
| 250 | return _('No statement of result pdf file uploaded.') |
---|
[17106] | 251 | if self.target is not None \ |
---|
| 252 | and self.target.startswith('tscf') \ |
---|
| 253 | and not store.getFileByContext(self.context, attr=u'not_reg.pdf'): |
---|
| 254 | return _('No notification of result pdf file uploaded.') |
---|
[17041] | 255 | #if self.target is not None \ |
---|
| 256 | # and self.target.startswith('tsc') \ |
---|
[17043] | 257 | # and not store.getFileByContext(self.context, attr=u'testimonial.pdf'): |
---|
| 258 | # return _('No testimonial pdf file uploaded.') |
---|
[17041] | 259 | return False |
---|
| 260 | |
---|
| 261 | class ResultStatement(AdditionalFile): |
---|
| 262 | grok.name('res_stat') |
---|
[17106] | 263 | |
---|
| 264 | class Testimonial(AdditionalFile): |
---|
| 265 | grok.name('testimonial') |
---|
[17041] | 266 | |
---|
[17106] | 267 | class NotificationResult(AdditionalFile): |
---|
| 268 | grok.name('not_res') |
---|
[17095] | 269 | |
---|
[17106] | 270 | class DocumentUploadForm(AdditionalFile): |
---|
| 271 | grok.name('docupload') |
---|
| 272 | |
---|
[17095] | 273 | class OtherDocument1(AdditionalFile): |
---|
[17106] | 274 | grok.name('doc_1') |
---|
[17095] | 275 | |
---|
[17169] | 276 | class OtherDocument2(AdditionalFile): |
---|
[17106] | 277 | grok.name('doc_2') |
---|