[10132] | 1 | ## $Id: browser.py 14058 2016-08-08 08:24:34Z 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 | from zope.component import getUtility |
---|
| 22 | from zope.i18n import translate |
---|
| 23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
| 24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[10847] | 25 | from waeup.kofa.applicants.interfaces import ( |
---|
| 26 | IApplicant, IApplicantEdit, ISpecialApplicant) |
---|
[10132] | 27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
[10134] | 28 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
| 29 | ApplicantsContainerPage) |
---|
[10132] | 30 | from waeup.kofa.applicants.viewlets import ( |
---|
| 31 | PaymentReceiptActionButton, PDFActionButton) |
---|
| 32 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
| 33 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 34 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 35 | UG_OMIT_PDF_FIELDS, |
---|
| 36 | UG_OMIT_MANAGE_FIELDS, |
---|
| 37 | UG_OMIT_EDIT_FIELDS |
---|
| 38 | ) |
---|
| 39 | from waeup.kwarapoly.applicants.interfaces import ( |
---|
| 40 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
| 41 | ND_OMIT_DISPLAY_FIELDS, |
---|
| 42 | ND_OMIT_PDF_FIELDS, |
---|
| 43 | ND_OMIT_MANAGE_FIELDS, |
---|
| 44 | ND_OMIT_EDIT_FIELDS |
---|
| 45 | ) |
---|
| 46 | |
---|
[10590] | 47 | UG_OMIT_EDIT_FIELDS = [ |
---|
| 48 | value for value in UG_OMIT_EDIT_FIELDS |
---|
[13187] | 49 | if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')] |
---|
[10590] | 50 | |
---|
[10643] | 51 | PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [ |
---|
[10628] | 52 | 'firstname', |
---|
| 53 | 'middlename', |
---|
| 54 | 'lastname', |
---|
[12142] | 55 | #'sex', |
---|
[10629] | 56 | 'jamb_score' |
---|
[10628] | 57 | ] |
---|
| 58 | |
---|
[10134] | 59 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
| 60 | """The standard view for regular applicant containers. |
---|
| 61 | """ |
---|
| 62 | |
---|
| 63 | @property |
---|
| 64 | def form_fields(self): |
---|
| 65 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
| 66 | if self.request.principal.id == 'zope.anybody': |
---|
| 67 | return form_fields.omit('application_fee') |
---|
| 68 | return form_fields |
---|
| 69 | |
---|
[10132] | 70 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
| 71 | """A display view for applicant data. |
---|
| 72 | """ |
---|
| 73 | |
---|
| 74 | @property |
---|
| 75 | def form_fields(self): |
---|
[10844] | 76 | if self.context.special: |
---|
[10847] | 77 | return grok.AutoFields(ISpecialApplicant) |
---|
[10132] | 78 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 79 | if self.context.is_nd: |
---|
| 80 | for field in ND_OMIT_DISPLAY_FIELDS: |
---|
| 81 | form_fields = form_fields.omit(field) |
---|
| 82 | else: |
---|
| 83 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 84 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 85 | form_fields = form_fields.omit(field) |
---|
| 86 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
[10590] | 87 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
[10132] | 88 | if not getattr(self.context, 'student_id'): |
---|
| 89 | form_fields = form_fields.omit('student_id') |
---|
| 90 | if not getattr(self.context, 'screening_score'): |
---|
| 91 | form_fields = form_fields.omit('screening_score') |
---|
| 92 | if not getattr(self.context, 'screening_venue'): |
---|
| 93 | form_fields = form_fields.omit('screening_venue') |
---|
| 94 | if not getattr(self.context, 'screening_date'): |
---|
| 95 | form_fields = form_fields.omit('screening_date') |
---|
| 96 | return form_fields |
---|
| 97 | |
---|
| 98 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
| 99 | |
---|
| 100 | def _reduced_slip(self): |
---|
| 101 | return getattr(self.context, 'result_uploaded', False) |
---|
| 102 | |
---|
| 103 | @property |
---|
[14058] | 104 | def note(self): |
---|
| 105 | note = getattr(self.context.__parent__, 'application_slip_notice', None) |
---|
| 106 | if note: |
---|
| 107 | return '<br /><br />' + note |
---|
| 108 | pronoun = 'S/he' |
---|
| 109 | if self.context.sex == 'm': |
---|
| 110 | pronoun = 'He' |
---|
| 111 | else: |
---|
| 112 | pronoun = 'She' |
---|
| 113 | return '''<br /><br /> |
---|
| 114 | The applicant has declared that: |
---|
| 115 | |
---|
| 116 | a) %s is not a member of any secret cult and will not join any. |
---|
| 117 | b) %s will not engage in any cult activities. |
---|
| 118 | c) %s will not be involved in any acts of terrorism, rape, robbery, fighting, illegal gathering and |
---|
| 119 | any activities that could disrupt peace on campus. |
---|
| 120 | d) %s does not have and will not acquire any form of weapon, fire arms, gun knife or any weapon |
---|
| 121 | that can cause damage to life and property. |
---|
| 122 | e) %s will strive to be worthy in character and learning at all times. |
---|
| 123 | |
---|
| 124 | The applicant has acknowledged that offences will automatically lead to the expulsion from the |
---|
| 125 | Polytechnic and also be dealt with in accordance with the law of the land. |
---|
| 126 | |
---|
| 127 | The applicant promises to abide by all the Rules and Regulations of the Polytechnic if offered |
---|
| 128 | admission. |
---|
| 129 | ''' % ( |
---|
| 130 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
| 131 | |
---|
| 132 | @property |
---|
[10132] | 133 | def form_fields(self): |
---|
| 134 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 135 | if self.context.is_nd: |
---|
| 136 | for field in ND_OMIT_PDF_FIELDS: |
---|
| 137 | form_fields = form_fields.omit(field) |
---|
| 138 | else: |
---|
| 139 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 140 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 141 | form_fields = form_fields.omit(field) |
---|
| 142 | if not getattr(self.context, 'student_id'): |
---|
| 143 | form_fields = form_fields.omit('student_id') |
---|
| 144 | if not getattr(self.context, 'screening_score'): |
---|
| 145 | form_fields = form_fields.omit('screening_score') |
---|
| 146 | if not getattr(self.context, 'screening_venue'): |
---|
| 147 | form_fields = form_fields.omit('screening_venue') |
---|
| 148 | if not getattr(self.context, 'screening_date'): |
---|
| 149 | form_fields = form_fields.omit('screening_date') |
---|
| 150 | return form_fields |
---|
| 151 | |
---|
| 152 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
| 153 | """A full edit view for applicant data. |
---|
| 154 | """ |
---|
| 155 | |
---|
| 156 | @property |
---|
| 157 | def form_fields(self): |
---|
[10844] | 158 | if self.context.special: |
---|
[11656] | 159 | form_fields = grok.AutoFields(ISpecialApplicant) |
---|
| 160 | form_fields['applicant_id'].for_display = True |
---|
| 161 | return form_fields |
---|
[10132] | 162 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 163 | if self.context.is_nd: |
---|
| 164 | for field in ND_OMIT_MANAGE_FIELDS: |
---|
| 165 | form_fields = form_fields.omit(field) |
---|
| 166 | else: |
---|
| 167 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 168 | form_fields = form_fields.omit(field) |
---|
| 169 | form_fields['student_id'].for_display = True |
---|
| 170 | form_fields['applicant_id'].for_display = True |
---|
| 171 | return form_fields |
---|
| 172 | |
---|
| 173 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
| 174 | """An applicant-centered edit view for applicant data. |
---|
| 175 | """ |
---|
| 176 | |
---|
| 177 | @property |
---|
| 178 | def form_fields(self): |
---|
[10844] | 179 | |
---|
| 180 | if self.context.special: |
---|
[11656] | 181 | form_fields = grok.AutoFields(ISpecialApplicant).omit( |
---|
| 182 | 'locked', 'suspended') |
---|
| 183 | form_fields['applicant_id'].for_display = True |
---|
| 184 | return form_fields |
---|
[10132] | 185 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 186 | if self.context.is_nd: |
---|
| 187 | for field in ND_OMIT_EDIT_FIELDS: |
---|
| 188 | form_fields = form_fields.omit(field) |
---|
[10643] | 189 | elif self.target is not None and self.target.startswith('pre'): |
---|
| 190 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
[10628] | 191 | form_fields = form_fields.omit(field) |
---|
[10132] | 192 | else: |
---|
| 193 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 194 | form_fields = form_fields.omit(field) |
---|
| 195 | form_fields['applicant_id'].for_display = True |
---|
| 196 | form_fields['reg_number'].for_display = True |
---|
| 197 | return form_fields |
---|