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