[10132] | 1 | ## $Id: browser.py 10643 2013-09-23 15:30:56Z 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 |
---|
| 25 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
[10134] | 26 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
| 27 | ApplicantsContainerPage) |
---|
[10132] | 28 | from waeup.kofa.applicants.viewlets import ( |
---|
| 29 | PaymentReceiptActionButton, PDFActionButton) |
---|
| 30 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
| 31 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 32 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 33 | UG_OMIT_PDF_FIELDS, |
---|
| 34 | UG_OMIT_MANAGE_FIELDS, |
---|
| 35 | UG_OMIT_EDIT_FIELDS |
---|
| 36 | ) |
---|
| 37 | from waeup.kwarapoly.applicants.interfaces import ( |
---|
| 38 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
| 39 | ND_OMIT_DISPLAY_FIELDS, |
---|
| 40 | ND_OMIT_PDF_FIELDS, |
---|
| 41 | ND_OMIT_MANAGE_FIELDS, |
---|
| 42 | ND_OMIT_EDIT_FIELDS |
---|
| 43 | ) |
---|
| 44 | |
---|
[10590] | 45 | UG_OMIT_EDIT_FIELDS = [ |
---|
| 46 | value for value in UG_OMIT_EDIT_FIELDS |
---|
| 47 | if not value in ('jamb_subjects', 'jamb_score')] |
---|
| 48 | |
---|
[10643] | 49 | PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [ |
---|
[10628] | 50 | 'firstname', |
---|
| 51 | 'middlename', |
---|
| 52 | 'lastname', |
---|
[10629] | 53 | 'sex', |
---|
| 54 | 'jamb_score' |
---|
[10628] | 55 | ] |
---|
| 56 | |
---|
[10134] | 57 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
| 58 | """The standard view for regular applicant containers. |
---|
| 59 | """ |
---|
| 60 | |
---|
| 61 | @property |
---|
| 62 | def form_fields(self): |
---|
| 63 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
| 64 | if self.request.principal.id == 'zope.anybody': |
---|
| 65 | return form_fields.omit('application_fee') |
---|
| 66 | return form_fields |
---|
| 67 | |
---|
[10132] | 68 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
| 69 | """A display view for applicant data. |
---|
| 70 | """ |
---|
| 71 | |
---|
| 72 | @property |
---|
| 73 | def form_fields(self): |
---|
| 74 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 75 | if self.context.is_nd: |
---|
| 76 | for field in ND_OMIT_DISPLAY_FIELDS: |
---|
| 77 | form_fields = form_fields.omit(field) |
---|
| 78 | else: |
---|
| 79 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 80 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 81 | form_fields = form_fields.omit(field) |
---|
| 82 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
[10590] | 83 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
[10132] | 84 | if not getattr(self.context, 'student_id'): |
---|
| 85 | form_fields = form_fields.omit('student_id') |
---|
| 86 | if not getattr(self.context, 'screening_score'): |
---|
| 87 | form_fields = form_fields.omit('screening_score') |
---|
| 88 | if not getattr(self.context, 'screening_venue'): |
---|
| 89 | form_fields = form_fields.omit('screening_venue') |
---|
| 90 | if not getattr(self.context, 'screening_date'): |
---|
| 91 | form_fields = form_fields.omit('screening_date') |
---|
| 92 | return form_fields |
---|
| 93 | |
---|
| 94 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
| 95 | |
---|
| 96 | def _reduced_slip(self): |
---|
| 97 | return getattr(self.context, 'result_uploaded', False) |
---|
| 98 | |
---|
| 99 | @property |
---|
| 100 | def form_fields(self): |
---|
| 101 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 102 | if self.context.is_nd: |
---|
| 103 | for field in ND_OMIT_PDF_FIELDS: |
---|
| 104 | form_fields = form_fields.omit(field) |
---|
| 105 | else: |
---|
| 106 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 107 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 108 | form_fields = form_fields.omit(field) |
---|
| 109 | if not getattr(self.context, 'student_id'): |
---|
| 110 | form_fields = form_fields.omit('student_id') |
---|
| 111 | if not getattr(self.context, 'screening_score'): |
---|
| 112 | form_fields = form_fields.omit('screening_score') |
---|
| 113 | if not getattr(self.context, 'screening_venue'): |
---|
| 114 | form_fields = form_fields.omit('screening_venue') |
---|
| 115 | if not getattr(self.context, 'screening_date'): |
---|
| 116 | form_fields = form_fields.omit('screening_date') |
---|
| 117 | return form_fields |
---|
| 118 | |
---|
| 119 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
| 120 | """A full edit view for applicant data. |
---|
| 121 | """ |
---|
| 122 | |
---|
| 123 | @property |
---|
| 124 | def form_fields(self): |
---|
| 125 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 126 | if self.context.is_nd: |
---|
| 127 | for field in ND_OMIT_MANAGE_FIELDS: |
---|
| 128 | form_fields = form_fields.omit(field) |
---|
| 129 | else: |
---|
| 130 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 131 | form_fields = form_fields.omit(field) |
---|
| 132 | form_fields['student_id'].for_display = True |
---|
| 133 | form_fields['applicant_id'].for_display = True |
---|
| 134 | return form_fields |
---|
| 135 | |
---|
| 136 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
| 137 | """An applicant-centered edit view for applicant data. |
---|
| 138 | """ |
---|
| 139 | |
---|
| 140 | @property |
---|
| 141 | def form_fields(self): |
---|
| 142 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 143 | if self.context.is_nd: |
---|
| 144 | for field in ND_OMIT_EDIT_FIELDS: |
---|
| 145 | form_fields = form_fields.omit(field) |
---|
[10643] | 146 | elif self.target is not None and self.target.startswith('pre'): |
---|
| 147 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
[10628] | 148 | form_fields = form_fields.omit(field) |
---|
[10132] | 149 | else: |
---|
| 150 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 151 | form_fields = form_fields.omit(field) |
---|
| 152 | form_fields['applicant_id'].for_display = True |
---|
| 153 | form_fields['reg_number'].for_display = True |
---|
| 154 | return form_fields |
---|