[8012] | 1 | ## $Id: browser.py 8760 2012-06-19 11:14:52Z 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 |
---|
[8020] | 37 | from waeup.uniben.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, |
---|
[8530] | 43 | UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS) |
---|
[8020] | 44 | from waeup.uniben.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 | |
---|
[8569] | 67 | @property |
---|
| 68 | def note(self): |
---|
| 69 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 70 | if target is not None and not target.startswith('pg'): |
---|
| 71 | return _(u'<br /><br /><br />' |
---|
| 72 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
| 73 | return |
---|
[8551] | 74 | |
---|
[8017] | 75 | @property |
---|
| 76 | def form_fields(self): |
---|
| 77 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 78 | if target is not None and target.startswith('pg'): |
---|
[8519] | 79 | form_fields = grok.AutoFields(IPGApplicant) |
---|
[8551] | 80 | for field in PG_OMIT_PDF_FIELDS: |
---|
[8519] | 81 | form_fields = form_fields.omit(field) |
---|
[8017] | 82 | else: |
---|
[8519] | 83 | form_fields = grok.AutoFields(IUGApplicant) |
---|
[8551] | 84 | for field in UG_OMIT_PDF_FIELDS: |
---|
[8519] | 85 | form_fields = form_fields.omit(field) |
---|
[8017] | 86 | return form_fields |
---|
[8012] | 87 | |
---|
[8196] | 88 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
[8017] | 89 | """A display view for applicant data. |
---|
| 90 | """ |
---|
[8012] | 91 | |
---|
| 92 | @property |
---|
| 93 | def form_fields(self): |
---|
| 94 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 95 | if target is not None and target.startswith('pg'): |
---|
[8519] | 96 | form_fields = grok.AutoFields(IPGApplicant) |
---|
| 97 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
| 98 | form_fields = form_fields.omit(field) |
---|
[8012] | 99 | else: |
---|
[8519] | 100 | form_fields = grok.AutoFields(IUGApplicant) |
---|
| 101 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 102 | form_fields = form_fields.omit(field) |
---|
[8012] | 103 | return form_fields |
---|
| 104 | |
---|
[8196] | 105 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
[8012] | 106 | """A full edit view for applicant data. |
---|
| 107 | """ |
---|
[8017] | 108 | |
---|
| 109 | @property |
---|
| 110 | def form_fields(self): |
---|
| 111 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 112 | if target is not None and target.startswith('pg'): |
---|
| 113 | form_fields = grok.AutoFields(IPGApplicant) |
---|
[8519] | 114 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
| 115 | form_fields = form_fields.omit(field) |
---|
[8017] | 116 | else: |
---|
| 117 | form_fields = grok.AutoFields(IUGApplicant) |
---|
[8519] | 118 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 119 | form_fields = form_fields.omit(field) |
---|
[8017] | 120 | form_fields['student_id'].for_display = True |
---|
| 121 | form_fields['applicant_id'].for_display = True |
---|
| 122 | return form_fields |
---|
[8012] | 123 | |
---|
[8196] | 124 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
[8012] | 125 | """An applicant-centered edit view for applicant data. |
---|
| 126 | """ |
---|
[8017] | 127 | |
---|
| 128 | @property |
---|
| 129 | def form_fields(self): |
---|
| 130 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 131 | if target is not None and target.startswith('pg'): |
---|
[8519] | 132 | form_fields = grok.AutoFields(IPGApplicantEdit) |
---|
| 133 | for field in PG_OMIT_EDIT_FIELDS: |
---|
| 134 | form_fields = form_fields.omit(field) |
---|
[8530] | 135 | elif target is not None and target.startswith('putme'): |
---|
| 136 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
| 137 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
| 138 | form_fields = form_fields.omit(field) |
---|
[8017] | 139 | else: |
---|
[8519] | 140 | form_fields = grok.AutoFields(IUGApplicantEdit) |
---|
| 141 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 142 | form_fields = form_fields.omit(field) |
---|
[8017] | 143 | form_fields['applicant_id'].for_display = True |
---|
[8051] | 144 | form_fields['reg_number'].for_display = True |
---|
[8017] | 145 | return form_fields |
---|
[8247] | 146 | |
---|
| 147 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
| 148 | """ Page to view an online payment ticket |
---|
| 149 | """ |
---|
| 150 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8263] | 151 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
[8247] | 152 | form_fields[ |
---|
| 153 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 154 | form_fields[ |
---|
| 155 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8716] | 156 | #grok.template('payment_view') |
---|
[8247] | 157 | |
---|
[8716] | 158 | #@property |
---|
| 159 | #def transaction_code(self): |
---|
| 160 | # tcode = self.context.p_id |
---|
| 161 | # return tcode[len(tcode)-8:len(tcode)] |
---|
[8247] | 162 | |
---|
[8263] | 163 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
[8247] | 164 | """ Page to add an online payment ticket |
---|
| 165 | """ |
---|
| 166 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
| 167 | |
---|
[8259] | 168 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
| 169 | """Deliver a PDF slip of the context. |
---|
| 170 | """ |
---|
| 171 | grok.context(ICustomApplicantOnlinePayment) |
---|
[8292] | 172 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
[8259] | 173 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 174 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 175 | |
---|
[8716] | 176 | # @property |
---|
| 177 | # def note(self): |
---|
| 178 | # if self.context.p_state == 'paid': |
---|
| 179 | # return None |
---|
| 180 | # tcode = self.context.p_id |
---|
| 181 | # tcode = tcode[len(tcode)-8:len(tcode)] |
---|
| 182 | # amount = self.context.amount_auth |
---|
| 183 | # note = translate(_( |
---|
| 184 | # u"""<br /><br /><br /> |
---|
| 185 | #The tranzaction code is <strong>${a}</strong>.""", |
---|
| 186 | # mapping = {'a':tcode})) |
---|
| 187 | # return note |
---|
[8630] | 188 | |
---|
| 189 | class CustomApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
| 190 | """Captcha'd registration page for applicants. |
---|
| 191 | """ |
---|
| 192 | |
---|
[8760] | 193 | #def _redirect(self, email, password, applicant_id): |
---|
| 194 | # # Forward email and credentials to landing page. |
---|
| 195 | # self.redirect(self.url(self.context, 'registration_complete', |
---|
| 196 | # data = dict(email=email, password=password, |
---|
| 197 | # applicant_id=applicant_id))) |
---|
| 198 | # return |
---|