1 | ## $Id: browser.py 8259 2012-04-23 14:06:39Z 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 |
---|
24 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
25 | from waeup.kofa.applicants.interfaces import ( |
---|
26 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
28 | OnlinePaymentCallbackPage, ExportPDFPage, |
---|
29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, AcceptanceFeePaymentAddPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | ApplicantBaseDisplayFormPage) |
---|
34 | from waeup.kofa.applicants.viewlets import ( |
---|
35 | RequestCallbackActionButton, PaymentReceiptActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from waeup.uniben.applicants.interfaces import ( |
---|
38 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
39 | ICustomApplicantOnlinePayment) |
---|
40 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
41 | |
---|
42 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
43 | # """ Display the base package callback button in custom pages. |
---|
44 | # """ |
---|
45 | # grok.context(ICustomApplicantOnlinePayment) |
---|
46 | |
---|
47 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
48 | # """ Activate callback simulation view |
---|
49 | # """ |
---|
50 | # grok.context(ICustomApplicantOnlinePayment) |
---|
51 | |
---|
52 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
53 | """A breadcrumb for payments. |
---|
54 | """ |
---|
55 | grok.context(ICustomApplicantOnlinePayment) |
---|
56 | |
---|
57 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
58 | grok.order(4) |
---|
59 | grok.context(ICustomApplicantOnlinePayment) |
---|
60 | |
---|
61 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
62 | |
---|
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 |
---|
73 | |
---|
74 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
75 | """A display view for applicant data. |
---|
76 | """ |
---|
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 | |
---|
89 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
90 | """A full edit view for applicant data. |
---|
91 | """ |
---|
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 |
---|
103 | |
---|
104 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
105 | """An applicant-centered edit view for applicant data. |
---|
106 | """ |
---|
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', |
---|
114 | 'screening_score', 'screening_venue' |
---|
115 | ) |
---|
116 | else: |
---|
117 | form_fields = grok.AutoFields(IUGApplicantEdit).omit( |
---|
118 | 'locked', 'course_admitted', 'student_id', |
---|
119 | 'screening_score' |
---|
120 | ) |
---|
121 | form_fields['applicant_id'].for_display = True |
---|
122 | form_fields['reg_number'].for_display = True |
---|
123 | return form_fields |
---|
124 | |
---|
125 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
126 | """ Page to view an online payment ticket |
---|
127 | """ |
---|
128 | grok.context(ICustomApplicantOnlinePayment) |
---|
129 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit( |
---|
130 | 'surcharge_1', 'surcharge_2', 'surcharge_3', 'ac') |
---|
131 | form_fields[ |
---|
132 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
133 | form_fields[ |
---|
134 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
135 | grok.template('payment_view') |
---|
136 | |
---|
137 | @property |
---|
138 | def transaction_code(self): |
---|
139 | tcode = self.context.p_id |
---|
140 | return tcode[len(tcode)-8:len(tcode)] |
---|
141 | |
---|
142 | class CustomAcceptanceFeePaymentAddPage(AcceptanceFeePaymentAddPage): |
---|
143 | """ Page to add an online payment ticket |
---|
144 | """ |
---|
145 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
146 | |
---|
147 | def _fillCustomFields(self, payment, session_config): |
---|
148 | payment.surcharge_1 = session_config.surcharge_1 |
---|
149 | payment.surcharge_2 = session_config.surcharge_2 |
---|
150 | payment.surcharge_3 = session_config.surcharge_3 |
---|
151 | return payment |
---|
152 | |
---|
153 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
154 | """Deliver a PDF slip of the context. |
---|
155 | """ |
---|
156 | grok.context(ICustomApplicantOnlinePayment) |
---|
157 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment) |
---|
158 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
159 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
160 | |
---|
161 | @property |
---|
162 | def note(self): |
---|
163 | tcode = self.context.p_id |
---|
164 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
165 | amount = self.context.amount_auth |
---|
166 | note = translate(_( |
---|
167 | u"""<br /><br /><br /> |
---|
168 | The tranzaction code for eTranzact payments is <strong>${a}</strong>.""", |
---|
169 | mapping = {'a':tcode})) |
---|
170 | return note |
---|