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