1 | ## $Id: browser.py 8263 2012-04-24 15:37:51Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 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 | import grok |
---|
19 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
20 | from zope.component import getUtility |
---|
21 | from zope.i18n import translate |
---|
22 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
23 | from waeup.kofa.interfaces import IExtFileStore |
---|
24 | from waeup.kofa.browser.layout import action |
---|
25 | from waeup.kofa.students.browser import ( |
---|
26 | StudentPersonalDisplayFormPage, |
---|
27 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
28 | StudentClearanceDisplayFormPage, OnlinePaymentCallbackPage, |
---|
29 | ExportPDFClearanceSlipPage, StudentBaseManageFormPage, |
---|
30 | StudentBaseEditFormPage, StudentPersonalEditFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage) |
---|
33 | from waeup.kofa.students.viewlets import ( |
---|
34 | RequestCallbackActionButton, PaymentReceiptActionButton) |
---|
35 | from waeup.uniben.students.interfaces import ( |
---|
36 | ICustomStudentBase, ICustomStudent, ICustomStudentPersonal, |
---|
37 | ICustomUGStudentClearance,ICustomPGStudentClearance, |
---|
38 | ICustomStudentOnlinePayment, |
---|
39 | ) |
---|
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(ICustomStudentOnlinePayment) |
---|
46 | |
---|
47 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
48 | # """ Activate callback simulation view |
---|
49 | # """ |
---|
50 | # grok.context(ICustomStudentOnlinePayment) |
---|
51 | |
---|
52 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
53 | """A breadcrumb for payments. |
---|
54 | """ |
---|
55 | grok.context(ICustomStudentOnlinePayment) |
---|
56 | |
---|
57 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
58 | grok.order(4) |
---|
59 | grok.context(ICustomStudentOnlinePayment) |
---|
60 | |
---|
61 | class CustomStudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
62 | """ View to manage student base data |
---|
63 | """ |
---|
64 | form_fields = grok.AutoFields(ICustomStudentBase).omit('student_id') |
---|
65 | |
---|
66 | class CustomStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
67 | """ View to edit student base data |
---|
68 | """ |
---|
69 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
70 | 'email', 'phone') |
---|
71 | |
---|
72 | |
---|
73 | class CustomStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
74 | """ Page to display student personal data |
---|
75 | """ |
---|
76 | grok.context(ICustomStudent) |
---|
77 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
78 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
79 | |
---|
80 | |
---|
81 | class CustomStudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
82 | """ Page to edit personal data |
---|
83 | """ |
---|
84 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
85 | |
---|
86 | |
---|
87 | class CustomStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
88 | """ Page to display student clearance data |
---|
89 | """ |
---|
90 | grok.context(ICustomStudent) |
---|
91 | |
---|
92 | @property |
---|
93 | def form_fields(self): |
---|
94 | cm = getattr(self.context,'current_mode', None) |
---|
95 | if cm is not None and cm.startswith('pg'): |
---|
96 | form_fields = grok.AutoFields( |
---|
97 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
98 | else: |
---|
99 | form_fields = grok.AutoFields( |
---|
100 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
101 | return form_fields |
---|
102 | |
---|
103 | class CustomExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
104 | """Deliver a PDF slip of the context. |
---|
105 | """ |
---|
106 | grok.context(ICustomStudent) |
---|
107 | |
---|
108 | @property |
---|
109 | def form_fields(self): |
---|
110 | cm = getattr(self.context,'current_mode', None) |
---|
111 | if cm is not None and cm.startswith('pg'): |
---|
112 | form_fields = grok.AutoFields( |
---|
113 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
114 | else: |
---|
115 | form_fields = grok.AutoFields( |
---|
116 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
117 | return form_fields |
---|
118 | |
---|
119 | class CustomStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
120 | """ Page to edit student clearance data |
---|
121 | """ |
---|
122 | grok.context(ICustomStudent) |
---|
123 | |
---|
124 | @property |
---|
125 | def form_fields(self): |
---|
126 | cm = getattr(self.context,'current_mode', None) |
---|
127 | if cm is not None and cm.startswith('pg'): |
---|
128 | form_fields = grok.AutoFields(ICustomPGStudentClearance) |
---|
129 | else: |
---|
130 | form_fields = grok.AutoFields(ICustomUGStudentClearance) |
---|
131 | return form_fields |
---|
132 | |
---|
133 | class CustomStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
134 | """ View to edit student clearance data by student |
---|
135 | """ |
---|
136 | grok.context(ICustomStudent) |
---|
137 | |
---|
138 | @property |
---|
139 | def form_fields(self): |
---|
140 | cm = getattr(self.context,'current_mode', None) |
---|
141 | if cm is not None and cm.startswith('pg'): |
---|
142 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit('clearance_locked') |
---|
143 | else: |
---|
144 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit('clearance_locked') |
---|
145 | return form_fields |
---|
146 | |
---|
147 | def dataNotComplete(self): |
---|
148 | store = getUtility(IExtFileStore) |
---|
149 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
150 | return _('No birth certificate uploaded.') |
---|
151 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
152 | return _('No referee letter uploaded.') |
---|
153 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
154 | return _('No acceptance letter uploaded.') |
---|
155 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
156 | return _('No first sitting result uploaded.') |
---|
157 | return False |
---|
158 | |
---|
159 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
160 | """ Page to view an online payment ticket |
---|
161 | """ |
---|
162 | grok.context(ICustomStudentOnlinePayment) |
---|
163 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
164 | form_fields[ |
---|
165 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
166 | form_fields[ |
---|
167 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
168 | grok.template('payment_view') |
---|
169 | |
---|
170 | @property |
---|
171 | def transaction_code(self): |
---|
172 | tcode = self.context.p_id |
---|
173 | return tcode[len(tcode)-8:len(tcode)] |
---|
174 | |
---|
175 | class CustomOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
176 | """ Page to add an online payment ticket |
---|
177 | """ |
---|
178 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
179 | 'p_category') |
---|
180 | factory = u'waeup.CustomStudentOnlinePayment' |
---|
181 | |
---|
182 | def _fillCustomFields(self, payment, pay_details): |
---|
183 | # No custom fields at the moment |
---|
184 | return payment |
---|
185 | |
---|
186 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
187 | """Deliver a PDF slip of the context. |
---|
188 | """ |
---|
189 | grok.context(ICustomStudentOnlinePayment) |
---|
190 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
191 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
192 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
193 | |
---|
194 | @property |
---|
195 | def note(self): |
---|
196 | tcode = self.context.p_id |
---|
197 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
198 | amount = self.context.amount_auth |
---|
199 | note = translate(_( |
---|
200 | u"""<br /><br /><br /> |
---|
201 | The tranzaction code for eTranzact payments is <strong>${a}</strong>.""", |
---|
202 | mapping = {'a':tcode})) |
---|
203 | return note |
---|