[8926] | 1 | ## $Id: browser.py 10377 2013-06-25 04:02:35Z 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 |
---|
[9054] | 24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[8926] | 25 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
| 26 | from waeup.kofa.applicants.interfaces import ( |
---|
| 27 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
| 28 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
| 29 | ExportPDFPage, |
---|
| 30 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
| 31 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
| 32 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
| 33 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
| 34 | ApplicantBaseDisplayFormPage) |
---|
| 35 | from waeup.kofa.applicants.viewlets import ( |
---|
| 36 | PaymentReceiptActionButton, PDFActionButton) |
---|
| 37 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
| 38 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 39 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
| 40 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
[9049] | 41 | INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit, |
---|
[9054] | 42 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 43 | UG_OMIT_PDF_FIELDS, |
---|
| 44 | UG_OMIT_MANAGE_FIELDS, |
---|
| 45 | UG_OMIT_EDIT_FIELDS, |
---|
| 46 | PG_OMIT_DISPLAY_FIELDS, |
---|
| 47 | PG_OMIT_PDF_FIELDS, |
---|
| 48 | PG_OMIT_MANAGE_FIELDS, |
---|
| 49 | PG_OMIT_EDIT_FIELDS, |
---|
| 50 | PUTME_OMIT_DISPLAY_FIELDS, |
---|
| 51 | PUTME_OMIT_PDF_FIELDS, |
---|
| 52 | PUTME_OMIT_MANAGE_FIELDS, |
---|
| 53 | PUTME_OMIT_EDIT_FIELDS, |
---|
| 54 | PUTME_OMIT_RESULT_SLIP_FIELDS, |
---|
| 55 | PUDE_OMIT_DISPLAY_FIELDS, |
---|
| 56 | PUDE_OMIT_PDF_FIELDS, |
---|
| 57 | PUDE_OMIT_MANAGE_FIELDS, |
---|
| 58 | PUDE_OMIT_EDIT_FIELDS, |
---|
| 59 | PUDE_OMIT_RESULT_SLIP_FIELDS, |
---|
| 60 | ) |
---|
[8926] | 61 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
| 62 | |
---|
| 63 | class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
| 64 | """A breadcrumb for payments. |
---|
| 65 | """ |
---|
| 66 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 67 | |
---|
| 68 | class PDFActionButton(PDFActionButton): |
---|
| 69 | |
---|
| 70 | @property |
---|
| 71 | def text(self): |
---|
| 72 | if getattr(self.context, 'result_uploaded', False): |
---|
| 73 | return _('Download result slip') |
---|
| 74 | return _('Download application slip') |
---|
| 75 | |
---|
[9050] | 76 | class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
| 77 | """A display view for applicant data. |
---|
| 78 | """ |
---|
[8926] | 79 | |
---|
[10377] | 80 | def _not_paid(self): |
---|
| 81 | return self.context.state in ('initialized', 'started',) |
---|
| 82 | |
---|
[9050] | 83 | @property |
---|
| 84 | def form_fields(self): |
---|
[10223] | 85 | if self.target is not None and self.target.startswith('pg'): |
---|
[9050] | 86 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
| 87 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 88 | form_fields = form_fields.omit(field) |
---|
[10223] | 89 | elif self.target is not None and self.target.startswith('putme'): |
---|
[9050] | 90 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 91 | for field in PUTME_OMIT_DISPLAY_FIELDS: |
---|
| 92 | form_fields = form_fields.omit(field) |
---|
[10223] | 93 | elif self.target is not None and self.target.startswith('pude'): |
---|
[9054] | 94 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 95 | for field in PUDE_OMIT_DISPLAY_FIELDS: |
---|
| 96 | form_fields = form_fields.omit(field) |
---|
[9050] | 97 | else: |
---|
| 98 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 99 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 100 | form_fields = form_fields.omit(field) |
---|
[9072] | 101 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
[9054] | 102 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
[9076] | 103 | if not getattr(self.context, 'student_id'): |
---|
| 104 | form_fields = form_fields.omit('student_id') |
---|
| 105 | if not getattr(self.context, 'screening_score'): |
---|
| 106 | form_fields = form_fields.omit('screening_score') |
---|
[10377] | 107 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
[9076] | 108 | form_fields = form_fields.omit('screening_venue') |
---|
[10377] | 109 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
[9076] | 110 | form_fields = form_fields.omit('screening_date') |
---|
[9050] | 111 | return form_fields |
---|
| 112 | |
---|
[8926] | 113 | class NigeriaPDFApplicationSlip(PDFApplicationSlip): |
---|
| 114 | |
---|
| 115 | def _reduced_slip(self): |
---|
| 116 | return getattr(self.context, 'result_uploaded', False) |
---|
| 117 | |
---|
| 118 | @property |
---|
| 119 | def form_fields(self): |
---|
[10223] | 120 | if self.target is not None and self.target.startswith('pg'): |
---|
[8926] | 121 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
| 122 | for field in PG_OMIT_PDF_FIELDS: |
---|
| 123 | form_fields = form_fields.omit(field) |
---|
[10223] | 124 | elif self.target is not None and self.target.startswith('putme'): |
---|
[8926] | 125 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 126 | if self._reduced_slip(): |
---|
[9049] | 127 | for field in PUTME_OMIT_RESULT_SLIP_FIELDS: |
---|
[8926] | 128 | form_fields = form_fields.omit(field) |
---|
| 129 | else: |
---|
[9049] | 130 | for field in PUTME_OMIT_PDF_FIELDS: |
---|
[8926] | 131 | form_fields = form_fields.omit(field) |
---|
[10223] | 132 | elif self.target is not None and self.target.startswith('pude'): |
---|
[9054] | 133 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 134 | if self._reduced_slip(): |
---|
| 135 | for field in PUDE_OMIT_RESULT_SLIP_FIELDS: |
---|
| 136 | form_fields = form_fields.omit(field) |
---|
| 137 | else: |
---|
| 138 | for field in PUDE_OMIT_PDF_FIELDS: |
---|
| 139 | form_fields = form_fields.omit(field) |
---|
[9049] | 140 | else: |
---|
| 141 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 142 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 143 | form_fields = form_fields.omit(field) |
---|
[8926] | 144 | if not getattr(self.context, 'student_id'): |
---|
| 145 | form_fields = form_fields.omit('student_id') |
---|
[9076] | 146 | if not getattr(self.context, 'screening_score'): |
---|
| 147 | form_fields = form_fields.omit('screening_score') |
---|
| 148 | if not getattr(self.context, 'screening_venue'): |
---|
| 149 | form_fields = form_fields.omit('screening_venue') |
---|
| 150 | if not getattr(self.context, 'screening_date'): |
---|
| 151 | form_fields = form_fields.omit('screening_date') |
---|
[8926] | 152 | return form_fields |
---|
| 153 | |
---|
| 154 | class NigeriaApplicantManageFormPage(ApplicantManageFormPage): |
---|
| 155 | """A full edit view for applicant data. |
---|
| 156 | """ |
---|
| 157 | |
---|
| 158 | @property |
---|
| 159 | def form_fields(self): |
---|
[10223] | 160 | if self.target is not None and self.target.startswith('pg'): |
---|
[8926] | 161 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
| 162 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 163 | form_fields = form_fields.omit(field) |
---|
[10223] | 164 | elif self.target is not None and self.target.startswith('putme'): |
---|
[9049] | 165 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 166 | for field in PUTME_OMIT_MANAGE_FIELDS: |
---|
| 167 | form_fields = form_fields.omit(field) |
---|
[10223] | 168 | elif self.target is not None and self.target.startswith('pude'): |
---|
[9054] | 169 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 170 | for field in PUDE_OMIT_MANAGE_FIELDS: |
---|
| 171 | form_fields = form_fields.omit(field) |
---|
[8926] | 172 | else: |
---|
| 173 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
| 174 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 175 | form_fields = form_fields.omit(field) |
---|
| 176 | form_fields['student_id'].for_display = True |
---|
| 177 | form_fields['applicant_id'].for_display = True |
---|
| 178 | return form_fields |
---|
| 179 | |
---|
| 180 | class NigeriaApplicantEditFormPage(ApplicantEditFormPage): |
---|
| 181 | """An applicant-centered edit view for applicant data. |
---|
| 182 | """ |
---|
| 183 | |
---|
| 184 | @property |
---|
| 185 | def form_fields(self): |
---|
[10223] | 186 | if self.target is not None and self.target.startswith('pg'): |
---|
[8926] | 187 | form_fields = grok.AutoFields(INigeriaPGApplicantEdit) |
---|
| 188 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 189 | form_fields = form_fields.omit(field) |
---|
[10223] | 190 | elif self.target is not None and self.target.startswith('putme'): |
---|
[8926] | 191 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
| 192 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
| 193 | form_fields = form_fields.omit(field) |
---|
[10223] | 194 | elif self.target is not None and self.target.startswith('pude'): |
---|
[9482] | 195 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
[9054] | 196 | for field in PUDE_OMIT_EDIT_FIELDS: |
---|
| 197 | form_fields = form_fields.omit(field) |
---|
[8926] | 198 | else: |
---|
| 199 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
| 200 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 201 | form_fields = form_fields.omit(field) |
---|
| 202 | form_fields['applicant_id'].for_display = True |
---|
| 203 | form_fields['reg_number'].for_display = True |
---|
| 204 | return form_fields |
---|
| 205 | |
---|
| 206 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
| 207 | """ Page to view an online payment ticket |
---|
| 208 | """ |
---|
| 209 | grok.context(INigeriaApplicantOnlinePayment) |
---|
[9985] | 210 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac', |
---|
| 211 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8926] | 212 | form_fields[ |
---|
| 213 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 214 | form_fields[ |
---|
| 215 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 216 | |
---|
| 217 | class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
| 218 | """Deliver a PDF slip of the context. |
---|
| 219 | """ |
---|
| 220 | grok.context(INigeriaApplicantOnlinePayment) |
---|
[9985] | 221 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit( |
---|
| 222 | 'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8926] | 223 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 224 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 225 | |
---|
| 226 | class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
| 227 | """Captcha'd registration page for applicants. |
---|
| 228 | """ |
---|
| 229 | |
---|
| 230 | #def _redirect(self, email, password, applicant_id): |
---|
| 231 | # # Forward email and credentials to landing page. |
---|
| 232 | # self.redirect(self.url(self.context, 'registration_complete', |
---|
| 233 | # data = dict(email=email, password=password, |
---|
| 234 | # applicant_id=applicant_id))) |
---|
| 235 | # return |
---|