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