1 | ## $Id: browser.py 8444 2012-05-14 10:04:25Z 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 | ExportPDFPage, |
---|
29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | ApplicantBaseDisplayFormPage) |
---|
34 | from waeup.kofa.applicants.viewlets import ( |
---|
35 | PaymentReceiptActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from waeup.aaue.applicants.interfaces import ( |
---|
38 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
39 | ICustomApplicantOnlinePayment) |
---|
40 | from waeup.aaue.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('ac') |
---|
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 | |
---|
141 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
142 | """ Page to add an online payment ticket |
---|
143 | """ |
---|
144 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
145 | |
---|
146 | def _fillCustomFields(self, payment, session_config): |
---|
147 | # No custom fields at the moment |
---|
148 | return payment |
---|
149 | |
---|
150 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
151 | """Deliver a PDF slip of the context. |
---|
152 | """ |
---|
153 | grok.context(ICustomApplicantOnlinePayment) |
---|
154 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
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 | if self.context.p_state == 'paid': |
---|
161 | return None |
---|
162 | tcode = self.context.p_id |
---|
163 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
164 | amount = self.context.amount_auth |
---|
165 | note = translate(_( |
---|
166 | u"""<br /><br /><br /> |
---|
167 | The tranzaction code for eTranzact payments is <strong>${a}</strong>.""", |
---|
168 | mapping = {'a':tcode})) |
---|
169 | return note |
---|