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