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