[8012] | 1 | ## $Id: browser.py 8806 2012-06-26 07:46:43Z 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 |
---|
[8259] | 21 | from zope.component import getUtility |
---|
| 22 | from zope.i18n import translate |
---|
[8247] | 23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[8259] | 24 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8090] | 25 | from waeup.kofa.applicants.interfaces import ( |
---|
| 26 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
[8012] | 27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
[8421] | 28 | ExportPDFPage, |
---|
[8090] | 29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
[8247] | 30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
[8263] | 31 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
[8259] | 32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
| 33 | ApplicantBaseDisplayFormPage) |
---|
| 34 | from waeup.kofa.applicants.viewlets import ( |
---|
[8806] | 35 | PaymentReceiptActionButton, PDFActionButton) |
---|
[8017] | 36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
[8619] | 37 | from waeup.futminna.applicants.interfaces import ( |
---|
[8247] | 38 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
[8530] | 39 | ICustomApplicantOnlinePayment, IPUTMEApplicantEdit, |
---|
[8519] | 40 | UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS, |
---|
[8551] | 41 | UG_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS, |
---|
[8519] | 42 | UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS, |
---|
[8806] | 43 | UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS, |
---|
| 44 | UG_OMIT_RESULT_SLIP_FIELDS) |
---|
[8619] | 45 | from waeup.futminna.interfaces import MessageFactory as _ |
---|
[8012] | 46 | |
---|
[8247] | 47 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
[8259] | 48 | # """ Display the base package callback button in custom pages. |
---|
[8247] | 49 | # """ |
---|
[8259] | 50 | # grok.context(ICustomApplicantOnlinePayment) |
---|
[8012] | 51 | |
---|
[8247] | 52 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
[8259] | 53 | # """ Activate callback simulation view |
---|
[8247] | 54 | # """ |
---|
[8259] | 55 | # grok.context(ICustomApplicantOnlinePayment) |
---|
[8247] | 56 | |
---|
| 57 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
| 58 | """A breadcrumb for payments. |
---|
[8012] | 59 | """ |
---|
[8247] | 60 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8012] | 61 | |
---|
[8259] | 62 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
| 63 | grok.order(4) |
---|
| 64 | grok.context(ICustomApplicantOnlinePayment) |
---|
| 65 | |
---|
[8806] | 66 | class PDFActionButton(PDFActionButton): |
---|
| 67 | |
---|
| 68 | @property |
---|
| 69 | def text(self): |
---|
| 70 | if getattr(self.context, 'result_uploaded', False): |
---|
| 71 | return _('Download result slip') |
---|
| 72 | return _('Download application slip') |
---|
| 73 | |
---|
| 74 | |
---|
[8196] | 75 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
[8012] | 76 | |
---|
[8806] | 77 | def _reduced_slip(self): |
---|
| 78 | return getattr(self.context, 'result_uploaded', False) |
---|
| 79 | |
---|
[8569] | 80 | @property |
---|
| 81 | def note(self): |
---|
| 82 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
[8806] | 83 | if target is not None and not target.startswith('pg') \ |
---|
| 84 | and not self._reduced_slip(): |
---|
[8569] | 85 | return _(u'<br /><br /><br />' |
---|
| 86 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
| 87 | return |
---|
[8551] | 88 | |
---|
[8017] | 89 | @property |
---|
| 90 | def form_fields(self): |
---|
| 91 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 92 | if target is not None and target.startswith('pg'): |
---|
[8519] | 93 | form_fields = grok.AutoFields(IPGApplicant) |
---|
[8551] | 94 | for field in PG_OMIT_PDF_FIELDS: |
---|
[8519] | 95 | form_fields = form_fields.omit(field) |
---|
[8017] | 96 | else: |
---|
[8519] | 97 | form_fields = grok.AutoFields(IUGApplicant) |
---|
[8806] | 98 | if self._reduced_slip(): |
---|
| 99 | for field in UG_OMIT_RESULT_SLIP_FIELDS: |
---|
| 100 | form_fields = form_fields.omit(field) |
---|
| 101 | else: |
---|
| 102 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 103 | form_fields = form_fields.omit(field) |
---|
| 104 | if not getattr(self.context, 'student_id'): |
---|
| 105 | form_fields = form_fields.omit('student_id') |
---|
[8017] | 106 | return form_fields |
---|
[8012] | 107 | |
---|
[8196] | 108 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
[8017] | 109 | """A display view for applicant data. |
---|
| 110 | """ |
---|
[8012] | 111 | |
---|
| 112 | @property |
---|
| 113 | def form_fields(self): |
---|
| 114 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 115 | if target is not None and target.startswith('pg'): |
---|
[8519] | 116 | form_fields = grok.AutoFields(IPGApplicant) |
---|
| 117 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 118 | form_fields = form_fields.omit(field) |
---|
[8012] | 119 | else: |
---|
[8519] | 120 | form_fields = grok.AutoFields(IUGApplicant) |
---|
| 121 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 122 | form_fields = form_fields.omit(field) |
---|
[8012] | 123 | return form_fields |
---|
| 124 | |
---|
[8196] | 125 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
[8012] | 126 | """A full edit view for applicant data. |
---|
| 127 | """ |
---|
[8017] | 128 | |
---|
| 129 | @property |
---|
| 130 | def form_fields(self): |
---|
| 131 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 132 | if target is not None and target.startswith('pg'): |
---|
| 133 | form_fields = grok.AutoFields(IPGApplicant) |
---|
[8519] | 134 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 135 | form_fields = form_fields.omit(field) |
---|
[8017] | 136 | else: |
---|
| 137 | form_fields = grok.AutoFields(IUGApplicant) |
---|
[8519] | 138 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 139 | form_fields = form_fields.omit(field) |
---|
[8017] | 140 | form_fields['student_id'].for_display = True |
---|
| 141 | form_fields['applicant_id'].for_display = True |
---|
| 142 | return form_fields |
---|
[8012] | 143 | |
---|
[8196] | 144 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
[8012] | 145 | """An applicant-centered edit view for applicant data. |
---|
| 146 | """ |
---|
[8017] | 147 | |
---|
| 148 | @property |
---|
| 149 | def form_fields(self): |
---|
| 150 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 151 | if target is not None and target.startswith('pg'): |
---|
[8519] | 152 | form_fields = grok.AutoFields(IPGApplicantEdit) |
---|
| 153 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 154 | form_fields = form_fields.omit(field) |
---|
[8530] | 155 | elif target is not None and target.startswith('putme'): |
---|
| 156 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
| 157 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
| 158 | form_fields = form_fields.omit(field) |
---|
[8017] | 159 | else: |
---|
[8519] | 160 | form_fields = grok.AutoFields(IUGApplicantEdit) |
---|
| 161 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 162 | form_fields = form_fields.omit(field) |
---|
[8017] | 163 | form_fields['applicant_id'].for_display = True |
---|
[8051] | 164 | form_fields['reg_number'].for_display = True |
---|
[8017] | 165 | return form_fields |
---|
[8247] | 166 | |
---|
| 167 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
| 168 | """ Page to view an online payment ticket |
---|
| 169 | """ |
---|
| 170 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 171 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
[8247] | 172 | form_fields[ |
---|
| 173 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 174 | form_fields[ |
---|
| 175 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 176 | grok.template('payment_view') |
---|
| 177 | |
---|
| 178 | @property |
---|
| 179 | def transaction_code(self): |
---|
| 180 | tcode = self.context.p_id |
---|
| 181 | return tcode[len(tcode)-8:len(tcode)] |
---|
| 182 | |
---|
[8263] | 183 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
[8247] | 184 | """ Page to add an online payment ticket |
---|
| 185 | """ |
---|
| 186 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
| 187 | |
---|
[8259] | 188 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
| 189 | """Deliver a PDF slip of the context. |
---|
| 190 | """ |
---|
| 191 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8292] | 192 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
[8259] | 193 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 194 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 195 | |
---|
| 196 | @property |
---|
| 197 | def note(self): |
---|
[8292] | 198 | if self.context.p_state == 'paid': |
---|
| 199 | return None |
---|
[8259] | 200 | tcode = self.context.p_id |
---|
| 201 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
| 202 | amount = self.context.amount_auth |
---|
| 203 | note = translate(_( |
---|
| 204 | u"""<br /><br /><br /> |
---|
[8506] | 205 | The tranzaction code is <strong>${a}</strong>.""", |
---|
[8259] | 206 | mapping = {'a':tcode})) |
---|
| 207 | return note |
---|