[10298] | 1 | ## $Id: browser.py 13422 2015-11-09 17:16:43Z 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 |
---|
[10298] | 28 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
| 29 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 30 | NigeriaApplicantDisplayFormPage, |
---|
| 31 | NigeriaApplicantManageFormPage, |
---|
| 32 | NigeriaApplicantEditFormPage, |
---|
| 33 | NigeriaPDFApplicationSlip, |
---|
[10929] | 34 | NigeriaApplicantRegistrationPage, |
---|
[11755] | 35 | NigeriaExportPDFPaymentSlipPage, |
---|
[10298] | 36 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 37 | UG_OMIT_PDF_FIELDS, |
---|
| 38 | UG_OMIT_MANAGE_FIELDS, |
---|
[11291] | 39 | UG_OMIT_EDIT_FIELDS) |
---|
[10298] | 40 | from waeup.aaue.applicants.interfaces import ( |
---|
| 41 | ICustomApplicant, |
---|
| 42 | ICustomUGApplicant, |
---|
[11291] | 43 | ICustomUGApplicantEdit |
---|
| 44 | ) |
---|
[10298] | 45 | |
---|
[11291] | 46 | UG_OMIT_PDF_FIELDS = tuple([ |
---|
| 47 | element for element in UG_OMIT_PDF_FIELDS if not element == 'phone']) |
---|
[10331] | 48 | UG_OMIT_PDF_FIELDS += ('reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
| 49 | 'alr_results', 'notice') |
---|
[10298] | 50 | |
---|
[11291] | 51 | FP_OMIT_FIELDS = ('hq_type', 'hq_fname', 'hq_matric_no', |
---|
| 52 | 'hq_degree', 'hq_school', 'hq_session', 'hq_disc') |
---|
| 53 | FP_OMIT_DISPLAY_FIELDS = UG_OMIT_DISPLAY_FIELDS + FP_OMIT_FIELDS |
---|
| 54 | FP_OMIT_PDF_FIELDS = UG_OMIT_PDF_FIELDS + FP_OMIT_FIELDS |
---|
| 55 | FP_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + FP_OMIT_FIELDS |
---|
| 56 | FP_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + FP_OMIT_FIELDS |
---|
| 57 | |
---|
[10298] | 58 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 59 | """A display view for applicant data. |
---|
| 60 | """ |
---|
| 61 | |
---|
| 62 | @property |
---|
| 63 | def form_fields(self): |
---|
[11291] | 64 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 65 | if self.target is not None and self.target.startswith('fp'): |
---|
| 66 | for field in FP_OMIT_DISPLAY_FIELDS: |
---|
[10298] | 67 | form_fields = form_fields.omit(field) |
---|
| 68 | else: |
---|
| 69 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 70 | form_fields = form_fields.omit(field) |
---|
| 71 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 72 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 73 | if not getattr(self.context, 'student_id'): |
---|
| 74 | form_fields = form_fields.omit('student_id') |
---|
| 75 | if not getattr(self.context, 'screening_score'): |
---|
| 76 | form_fields = form_fields.omit('screening_score') |
---|
| 77 | if not getattr(self.context, 'screening_venue'): |
---|
| 78 | form_fields = form_fields.omit('screening_venue') |
---|
| 79 | if not getattr(self.context, 'screening_date'): |
---|
| 80 | form_fields = form_fields.omit('screening_date') |
---|
| 81 | return form_fields |
---|
| 82 | |
---|
| 83 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 84 | |
---|
[10311] | 85 | column_two_fields = ('applicant_id', 'reg_number', |
---|
| 86 | 'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth') |
---|
[10331] | 87 | two_columns_design_fields = [ |
---|
| 88 | 'fst_sit_fname', 'fst_sit_no', 'fst_sit_date', |
---|
| 89 | 'fst_sit_type', 'fst_sit_results', |
---|
| 90 | 'scd_sit_fname', 'scd_sit_no', 'scd_sit_date', |
---|
| 91 | 'scd_sit_type', 'scd_sit_results'] |
---|
[10311] | 92 | |
---|
[10301] | 93 | @property |
---|
| 94 | def note(self): |
---|
| 95 | if self.context.sex == 'm': |
---|
| 96 | pronoun = 'he' |
---|
| 97 | else: |
---|
| 98 | pronoun = 'she' |
---|
| 99 | return ''' |
---|
[10897] | 100 | The applicant has acknowledged that, if discovered at any time that %s does not possess |
---|
| 101 | any of the qualifications which %s claims %s has obtained, %s will be expelled from the |
---|
| 102 | University not be re-admitted for the same or any other programme, even if %s has |
---|
| 103 | upgraded previous and shall qualifications or possess additional qualifications. |
---|
[10331] | 104 | ''' % ( |
---|
[10301] | 105 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
[10298] | 106 | |
---|
| 107 | @property |
---|
| 108 | def form_fields(self): |
---|
[11291] | 109 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 110 | if self.target is not None and self.target.startswith('fp'): |
---|
| 111 | for field in FP_OMIT_PDF_FIELDS: |
---|
[10298] | 112 | form_fields = form_fields.omit(field) |
---|
| 113 | else: |
---|
| 114 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 115 | form_fields = form_fields.omit(field) |
---|
| 116 | if not getattr(self.context, 'student_id'): |
---|
| 117 | form_fields = form_fields.omit('student_id') |
---|
| 118 | if not getattr(self.context, 'screening_score'): |
---|
| 119 | form_fields = form_fields.omit('screening_score') |
---|
| 120 | if not getattr(self.context, 'screening_venue'): |
---|
| 121 | form_fields = form_fields.omit('screening_venue') |
---|
| 122 | if not getattr(self.context, 'screening_date'): |
---|
| 123 | form_fields = form_fields.omit('screening_date') |
---|
| 124 | return form_fields |
---|
| 125 | |
---|
| 126 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 127 | """A full edit view for applicant data. |
---|
| 128 | """ |
---|
| 129 | |
---|
| 130 | @property |
---|
| 131 | def form_fields(self): |
---|
[11291] | 132 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 133 | if self.target is not None and self.target.startswith('fp'): |
---|
| 134 | for field in FP_OMIT_MANAGE_FIELDS: |
---|
[10298] | 135 | form_fields = form_fields.omit(field) |
---|
| 136 | else: |
---|
| 137 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 138 | form_fields = form_fields.omit(field) |
---|
| 139 | form_fields['student_id'].for_display = True |
---|
| 140 | form_fields['applicant_id'].for_display = True |
---|
| 141 | return form_fields |
---|
| 142 | |
---|
| 143 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
| 144 | """An applicant-centered edit view for applicant data. |
---|
| 145 | """ |
---|
| 146 | |
---|
| 147 | @property |
---|
| 148 | def form_fields(self): |
---|
[11291] | 149 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 150 | if self.target is not None and self.target.startswith('fp'): |
---|
| 151 | for field in FP_OMIT_EDIT_FIELDS: |
---|
[10298] | 152 | form_fields = form_fields.omit(field) |
---|
| 153 | else: |
---|
| 154 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 155 | form_fields = form_fields.omit(field) |
---|
| 156 | form_fields['applicant_id'].for_display = True |
---|
| 157 | form_fields['reg_number'].for_display = True |
---|
| 158 | return form_fields |
---|
[10929] | 159 | |
---|
| 160 | class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage): |
---|
| 161 | """Captcha'd registration page for applicants. |
---|
| 162 | """ |
---|
| 163 | |
---|
| 164 | def _redirect(self, email, password, applicant_id): |
---|
| 165 | # Forward email and credentials to landing page. |
---|
| 166 | self.redirect(self.url(self.context, 'registration_complete', |
---|
| 167 | data = dict(email=email, password=password, |
---|
| 168 | applicant_id=applicant_id))) |
---|
[11755] | 169 | return |
---|
| 170 | |
---|
| 171 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
| 172 | |
---|
| 173 | @property |
---|
| 174 | def payment_slip_download_warning(self): |
---|
[13422] | 175 | return '' |
---|
| 176 | |
---|
| 177 | class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage): |
---|
| 178 | """Captcha'd status checking page for applicants. |
---|
| 179 | """ |
---|
| 180 | grok.template('applicantcheckstatus') |
---|