[10765] | 1 | ## $Id: browser.py 14865 2017-10-06 14:05:18Z 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 |
---|
[14721] | 21 | from zope.component import getUtility |
---|
| 22 | from zope.i18n import translate |
---|
[14807] | 23 | from hurry.workflow.interfaces import IWorkflowState |
---|
[14721] | 24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
| 25 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[14732] | 26 | from waeup.kofa.interfaces import IExtFileStore, IKofaUtils |
---|
[14721] | 27 | from waeup.kofa.applicants.interfaces import ( |
---|
[14865] | 28 | IApplicant, IApplicantEdit) |
---|
[14721] | 29 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
| 30 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
[14732] | 31 | ApplicantsContainerPage, ApplicationFeePaymentAddPage) |
---|
[14721] | 32 | from waeup.kofa.applicants.viewlets import ( |
---|
| 33 | PaymentReceiptActionButton, PDFActionButton) |
---|
| 34 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
[14807] | 35 | from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED |
---|
[14721] | 36 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 37 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 38 | UG_OMIT_PDF_FIELDS, |
---|
| 39 | UG_OMIT_MANAGE_FIELDS, |
---|
| 40 | UG_OMIT_EDIT_FIELDS |
---|
| 41 | ) |
---|
| 42 | from kofacustom.dspg.applicants.interfaces import ( |
---|
| 43 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
[14865] | 44 | ICustomSpecialApplicant, |
---|
[14721] | 45 | ND_OMIT_DISPLAY_FIELDS, |
---|
| 46 | ND_OMIT_PDF_FIELDS, |
---|
| 47 | ND_OMIT_MANAGE_FIELDS, |
---|
| 48 | ND_OMIT_EDIT_FIELDS |
---|
| 49 | ) |
---|
[10765] | 50 | |
---|
[14732] | 51 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
| 52 | |
---|
[14721] | 53 | UG_OMIT_EDIT_FIELDS = [ |
---|
| 54 | value for value in UG_OMIT_EDIT_FIELDS |
---|
| 55 | if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')] |
---|
[10765] | 56 | |
---|
[14721] | 57 | PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [ |
---|
| 58 | 'firstname', |
---|
| 59 | 'middlename', |
---|
| 60 | 'lastname', |
---|
| 61 | #'sex', |
---|
| 62 | 'jamb_score' |
---|
| 63 | ] |
---|
| 64 | |
---|
| 65 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
| 66 | """The standard view for regular applicant containers. |
---|
| 67 | """ |
---|
| 68 | |
---|
| 69 | @property |
---|
| 70 | def form_fields(self): |
---|
| 71 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
| 72 | if self.request.principal.id == 'zope.anybody': |
---|
| 73 | return form_fields.omit('application_fee') |
---|
| 74 | return form_fields |
---|
| 75 | |
---|
| 76 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
| 77 | """A display view for applicant data. |
---|
| 78 | """ |
---|
| 79 | |
---|
| 80 | @property |
---|
| 81 | def form_fields(self): |
---|
| 82 | if self.context.special: |
---|
[14865] | 83 | return grok.AutoFields(ICustomSpecialApplicant) |
---|
[14721] | 84 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 85 | if self.context.is_nd: |
---|
| 86 | for field in ND_OMIT_DISPLAY_FIELDS: |
---|
| 87 | form_fields = form_fields.omit(field) |
---|
| 88 | else: |
---|
| 89 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 90 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 91 | form_fields = form_fields.omit(field) |
---|
| 92 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 93 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
| 94 | if not getattr(self.context, 'student_id'): |
---|
| 95 | form_fields = form_fields.omit('student_id') |
---|
| 96 | if not getattr(self.context, 'screening_score'): |
---|
| 97 | form_fields = form_fields.omit('screening_score') |
---|
| 98 | if not getattr(self.context, 'screening_venue'): |
---|
| 99 | form_fields = form_fields.omit('screening_venue') |
---|
| 100 | if not getattr(self.context, 'screening_date'): |
---|
| 101 | form_fields = form_fields.omit('screening_date') |
---|
| 102 | return form_fields |
---|
| 103 | |
---|
| 104 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
| 105 | |
---|
| 106 | def _reduced_slip(self): |
---|
| 107 | return getattr(self.context, 'result_uploaded', False) |
---|
| 108 | |
---|
| 109 | @property |
---|
| 110 | def note(self): |
---|
| 111 | note = getattr(self.context.__parent__, 'application_slip_notice', None) |
---|
| 112 | if note: |
---|
| 113 | return '<br /><br />' + note |
---|
| 114 | pronoun = 'S/he' |
---|
| 115 | if self.context.sex == 'm': |
---|
| 116 | pronoun = 'He' |
---|
| 117 | else: |
---|
| 118 | pronoun = 'She' |
---|
| 119 | return '''<br /><br /> |
---|
| 120 | The applicant has declared that: |
---|
| 121 | |
---|
| 122 | a) %s is not a member of any secret cult and will not join any. |
---|
| 123 | b) %s will not engage in any cult activities. |
---|
| 124 | c) %s will not be involved in any acts of terrorism, rape, robbery, fighting, illegal gathering and |
---|
| 125 | any activities that could disrupt peace on campus. |
---|
| 126 | d) %s does not have and will not acquire any form of weapon, fire arms, gun knife or any weapon |
---|
| 127 | that can cause damage to life and property. |
---|
| 128 | e) %s will strive to be worthy in character and learning at all times. |
---|
| 129 | |
---|
| 130 | The applicant has acknowledged that offences will automatically lead to the expulsion from the |
---|
| 131 | Polytechnic and also be dealt with in accordance with the law of the land. |
---|
| 132 | |
---|
| 133 | The applicant promises to abide by all the Rules and Regulations of the Polytechnic if offered |
---|
| 134 | admission. |
---|
| 135 | ''' % ( |
---|
| 136 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
| 137 | |
---|
| 138 | @property |
---|
| 139 | def form_fields(self): |
---|
| 140 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 141 | if self.context.is_nd: |
---|
| 142 | for field in ND_OMIT_PDF_FIELDS: |
---|
| 143 | form_fields = form_fields.omit(field) |
---|
| 144 | else: |
---|
| 145 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 146 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 147 | form_fields = form_fields.omit(field) |
---|
| 148 | if not getattr(self.context, 'student_id'): |
---|
| 149 | form_fields = form_fields.omit('student_id') |
---|
| 150 | if not getattr(self.context, 'screening_score'): |
---|
| 151 | form_fields = form_fields.omit('screening_score') |
---|
| 152 | if not getattr(self.context, 'screening_venue'): |
---|
| 153 | form_fields = form_fields.omit('screening_venue') |
---|
| 154 | if not getattr(self.context, 'screening_date'): |
---|
| 155 | form_fields = form_fields.omit('screening_date') |
---|
| 156 | return form_fields |
---|
| 157 | |
---|
| 158 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
| 159 | """A full edit view for applicant data. |
---|
| 160 | """ |
---|
| 161 | |
---|
| 162 | @property |
---|
| 163 | def form_fields(self): |
---|
| 164 | if self.context.special: |
---|
[14865] | 165 | form_fields = grok.AutoFields(ICustomSpecialApplicant) |
---|
[14721] | 166 | form_fields['applicant_id'].for_display = True |
---|
| 167 | return form_fields |
---|
| 168 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 169 | if self.context.is_nd: |
---|
| 170 | for field in ND_OMIT_MANAGE_FIELDS: |
---|
| 171 | form_fields = form_fields.omit(field) |
---|
| 172 | else: |
---|
| 173 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 174 | form_fields = form_fields.omit(field) |
---|
| 175 | form_fields['student_id'].for_display = True |
---|
| 176 | form_fields['applicant_id'].for_display = True |
---|
| 177 | return form_fields |
---|
| 178 | |
---|
[14865] | 179 | def setUpWidgets(self, ignore_request=False): |
---|
| 180 | super(CustomApplicantManageFormPage,self).setUpWidgets(ignore_request) |
---|
| 181 | if self.context.special: |
---|
| 182 | self.widgets['carryover_courses'].height = 3 |
---|
| 183 | return |
---|
| 184 | |
---|
[14721] | 185 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
| 186 | """An applicant-centered edit view for applicant data. |
---|
| 187 | """ |
---|
| 188 | |
---|
[14807] | 189 | def unremovable(self, ticket): |
---|
| 190 | return True |
---|
| 191 | |
---|
[14721] | 192 | @property |
---|
| 193 | def form_fields(self): |
---|
| 194 | if self.context.special: |
---|
[14865] | 195 | form_fields = grok.AutoFields(ICustomSpecialApplicant).omit( |
---|
[14721] | 196 | 'locked', 'suspended') |
---|
| 197 | form_fields['applicant_id'].for_display = True |
---|
| 198 | return form_fields |
---|
| 199 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 200 | if self.context.is_nd: |
---|
| 201 | for field in ND_OMIT_EDIT_FIELDS: |
---|
| 202 | form_fields = form_fields.omit(field) |
---|
| 203 | elif self.target is not None and self.target.startswith('pre'): |
---|
| 204 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
| 205 | form_fields = form_fields.omit(field) |
---|
| 206 | else: |
---|
| 207 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 208 | form_fields = form_fields.omit(field) |
---|
| 209 | form_fields['applicant_id'].for_display = True |
---|
| 210 | form_fields['reg_number'].for_display = True |
---|
[14732] | 211 | return form_fields |
---|
| 212 | |
---|
[14865] | 213 | def setUpWidgets(self, ignore_request=False): |
---|
| 214 | super(CustomApplicantEditFormPage,self).setUpWidgets(ignore_request) |
---|
| 215 | if self.context.special: |
---|
| 216 | self.widgets['carryover_courses'].height = 3 |
---|
| 217 | return |
---|
| 218 | |
---|
[14807] | 219 | @property |
---|
| 220 | def display_actions(self): |
---|
| 221 | state = IWorkflowState(self.context).getState() |
---|
| 222 | # If the form is unlocked, applicants are allowed to save the form |
---|
| 223 | # and remove unused tickets. |
---|
| 224 | actions = [[_('Save')], []] |
---|
| 225 | # Only in state started they can also add tickets. |
---|
| 226 | if state == STARTED: |
---|
| 227 | actions = [[_('Save')], |
---|
| 228 | [_('Add online payment ticket'),]] |
---|
| 229 | # In state paid, they can submit the data and further add tickets |
---|
| 230 | # if the application is special. |
---|
| 231 | elif self.context.special and state == PAID: |
---|
| 232 | actions = [[_('Save'), _('Finally Submit')], |
---|
| 233 | [_('Add online payment ticket'),]] |
---|
| 234 | elif state == PAID: |
---|
| 235 | actions = [[_('Save'), _('Finally Submit')], []] |
---|
| 236 | return actions |
---|
| 237 | |
---|
[14732] | 238 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
| 239 | """ Page to add an online payment ticket |
---|
| 240 | """ |
---|
| 241 | |
---|
| 242 | @property |
---|
| 243 | def custom_requirements(self): |
---|
| 244 | store = getUtility(IExtFileStore) |
---|
| 245 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
| 246 | return _('Upload your passport photo before making payment.') |
---|
| 247 | return '' |
---|