[10298] | 1 | ## $Id: browser.py 10929 2014-01-15 12:50:07Z 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, |
---|
[10298] | 34 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 35 | UG_OMIT_PDF_FIELDS, |
---|
| 36 | UG_OMIT_MANAGE_FIELDS, |
---|
| 37 | UG_OMIT_EDIT_FIELDS, |
---|
| 38 | PG_OMIT_DISPLAY_FIELDS, |
---|
| 39 | PG_OMIT_PDF_FIELDS, |
---|
| 40 | PG_OMIT_MANAGE_FIELDS, |
---|
| 41 | PG_OMIT_EDIT_FIELDS) |
---|
| 42 | from waeup.aaue.applicants.interfaces import ( |
---|
| 43 | ICustomApplicant, |
---|
| 44 | ICustomUGApplicant, |
---|
| 45 | ICustomPGApplicant, |
---|
| 46 | ICustomPGApplicantEdit, |
---|
| 47 | ICustomUGApplicantEdit) |
---|
| 48 | |
---|
[10311] | 49 | UG_OMIT_PDF_FIELDS = [ |
---|
| 50 | element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'] |
---|
[10331] | 51 | UG_OMIT_PDF_FIELDS += ('reg_number','alr_fname', 'alr_no', 'alr_date', |
---|
| 52 | 'alr_results', 'notice') |
---|
[10298] | 53 | |
---|
| 54 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 55 | """A display view for applicant data. |
---|
| 56 | """ |
---|
| 57 | |
---|
| 58 | @property |
---|
| 59 | def form_fields(self): |
---|
| 60 | if self.target is not None and self.target.startswith('pg'): |
---|
| 61 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 62 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 63 | form_fields = form_fields.omit(field) |
---|
| 64 | else: |
---|
| 65 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 66 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 67 | form_fields = form_fields.omit(field) |
---|
| 68 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 69 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 70 | if not getattr(self.context, 'student_id'): |
---|
| 71 | form_fields = form_fields.omit('student_id') |
---|
| 72 | if not getattr(self.context, 'screening_score'): |
---|
| 73 | form_fields = form_fields.omit('screening_score') |
---|
| 74 | if not getattr(self.context, 'screening_venue'): |
---|
| 75 | form_fields = form_fields.omit('screening_venue') |
---|
| 76 | if not getattr(self.context, 'screening_date'): |
---|
| 77 | form_fields = form_fields.omit('screening_date') |
---|
| 78 | return form_fields |
---|
| 79 | |
---|
| 80 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 81 | |
---|
[10311] | 82 | column_two_fields = ('applicant_id', 'reg_number', |
---|
| 83 | 'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth') |
---|
[10331] | 84 | two_columns_design_fields = [ |
---|
| 85 | 'fst_sit_fname', 'fst_sit_no', 'fst_sit_date', |
---|
| 86 | 'fst_sit_type', 'fst_sit_results', |
---|
| 87 | 'scd_sit_fname', 'scd_sit_no', 'scd_sit_date', |
---|
| 88 | 'scd_sit_type', 'scd_sit_results'] |
---|
[10311] | 89 | |
---|
[10301] | 90 | @property |
---|
| 91 | def note(self): |
---|
| 92 | if self.context.sex == 'm': |
---|
| 93 | pronoun = 'he' |
---|
| 94 | else: |
---|
| 95 | pronoun = 'she' |
---|
| 96 | return ''' |
---|
[10897] | 97 | The applicant has acknowledged that, if discovered at any time that %s does not possess |
---|
| 98 | any of the qualifications which %s claims %s has obtained, %s will be expelled from the |
---|
| 99 | University not be re-admitted for the same or any other programme, even if %s has |
---|
| 100 | upgraded previous and shall qualifications or possess additional qualifications. |
---|
[10331] | 101 | ''' % ( |
---|
[10301] | 102 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
[10298] | 103 | |
---|
| 104 | @property |
---|
| 105 | def form_fields(self): |
---|
| 106 | if self.target is not None and self.target.startswith('pg'): |
---|
| 107 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 108 | for field in PG_OMIT_PDF_FIELDS: |
---|
| 109 | form_fields = form_fields.omit(field) |
---|
| 110 | else: |
---|
| 111 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 112 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 113 | form_fields = form_fields.omit(field) |
---|
| 114 | if not getattr(self.context, 'student_id'): |
---|
| 115 | form_fields = form_fields.omit('student_id') |
---|
| 116 | if not getattr(self.context, 'screening_score'): |
---|
| 117 | form_fields = form_fields.omit('screening_score') |
---|
| 118 | if not getattr(self.context, 'screening_venue'): |
---|
| 119 | form_fields = form_fields.omit('screening_venue') |
---|
| 120 | if not getattr(self.context, 'screening_date'): |
---|
| 121 | form_fields = form_fields.omit('screening_date') |
---|
| 122 | return form_fields |
---|
| 123 | |
---|
| 124 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 125 | """A full edit view for applicant data. |
---|
| 126 | """ |
---|
| 127 | |
---|
| 128 | @property |
---|
| 129 | def form_fields(self): |
---|
| 130 | if self.target is not None and self.target.startswith('pg'): |
---|
| 131 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
| 132 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 133 | form_fields = form_fields.omit(field) |
---|
| 134 | else: |
---|
| 135 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 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): |
---|
| 148 | if self.target is not None and self.target.startswith('pg'): |
---|
| 149 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
| 150 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 151 | form_fields = form_fields.omit(field) |
---|
| 152 | else: |
---|
| 153 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 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))) |
---|
| 169 | return |
---|