1 | ## $Id: browser.py 8904 2012-07-03 21:10:15Z 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, StudentPersonalManageFormPage, |
---|
27 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
28 | StudentClearanceDisplayFormPage, OnlinePaymentFakeApprovePage, |
---|
29 | ExportPDFClearanceSlipPage, StudentBaseManageFormPage, |
---|
30 | StudentBaseEditFormPage, StudentPersonalEditFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | StudentFilesUploadPage, emit_lock_message) |
---|
34 | from waeup.kofa.students.viewlets import ( |
---|
35 | PaymentReceiptActionButton, StudentPassportActionButton) |
---|
36 | from kofacustom.nigeria.students.interfaces import ( |
---|
37 | INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal, |
---|
38 | INigeriaUGStudentClearance,INigeriaPGStudentClearance, |
---|
39 | INigeriaStudentOnlinePayment |
---|
40 | ) |
---|
41 | from waeup.kofa.students.workflow import ADMITTED |
---|
42 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
43 | |
---|
44 | class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
45 | """A breadcrumb for payments. |
---|
46 | """ |
---|
47 | grok.context(INigeriaStudentOnlinePayment) |
---|
48 | |
---|
49 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
50 | grok.order(4) |
---|
51 | grok.context(INigeriaStudentOnlinePayment) |
---|
52 | |
---|
53 | class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
54 | """ View to manage student base data |
---|
55 | """ |
---|
56 | form_fields = grok.AutoFields(INigeriaStudentBase).omit('student_id') |
---|
57 | |
---|
58 | class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
59 | """ View to edit student base data |
---|
60 | """ |
---|
61 | form_fields = grok.AutoFields(INigeriaStudentBase).select( |
---|
62 | 'email', 'phone') |
---|
63 | |
---|
64 | |
---|
65 | class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
66 | """ Page to display student personal data |
---|
67 | """ |
---|
68 | form_fields = grok.AutoFields(INigeriaStudentPersonal) |
---|
69 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
70 | |
---|
71 | |
---|
72 | class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
73 | """ Page to edit personal data |
---|
74 | """ |
---|
75 | form_fields = grok.AutoFields(INigeriaStudentPersonal) |
---|
76 | |
---|
77 | |
---|
78 | class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage): |
---|
79 | """ Page to edit personal data |
---|
80 | """ |
---|
81 | form_fields = grok.AutoFields(INigeriaStudentPersonal) |
---|
82 | |
---|
83 | |
---|
84 | class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
85 | """ Page to display student clearance data |
---|
86 | """ |
---|
87 | |
---|
88 | @property |
---|
89 | def form_fields(self): |
---|
90 | cm = getattr(self.context,'current_mode', None) |
---|
91 | if cm is not None and cm.startswith('pg'): |
---|
92 | form_fields = grok.AutoFields( |
---|
93 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
94 | else: |
---|
95 | form_fields = grok.AutoFields( |
---|
96 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
97 | return form_fields |
---|
98 | |
---|
99 | class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
100 | """Deliver a PDF slip of the context. |
---|
101 | """ |
---|
102 | |
---|
103 | @property |
---|
104 | def form_fields(self): |
---|
105 | cm = getattr(self.context,'current_mode', None) |
---|
106 | if cm is not None and cm.startswith('pg'): |
---|
107 | form_fields = grok.AutoFields( |
---|
108 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
109 | else: |
---|
110 | form_fields = grok.AutoFields( |
---|
111 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
112 | return form_fields |
---|
113 | |
---|
114 | class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
115 | """ Page to edit student clearance data |
---|
116 | """ |
---|
117 | |
---|
118 | @property |
---|
119 | def form_fields(self): |
---|
120 | cm = getattr(self.context,'current_mode', None) |
---|
121 | if cm is not None and cm.startswith('pg'): |
---|
122 | form_fields = grok.AutoFields(INigeriaPGStudentClearance) |
---|
123 | else: |
---|
124 | form_fields = grok.AutoFields(INigeriaUGStudentClearance) |
---|
125 | return form_fields |
---|
126 | |
---|
127 | class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
128 | """ View to edit student clearance data by student |
---|
129 | """ |
---|
130 | |
---|
131 | @property |
---|
132 | def form_fields(self): |
---|
133 | cm = getattr(self.context,'current_mode', None) |
---|
134 | if cm is not None and cm.startswith('pg'): |
---|
135 | form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit('clearance_locked') |
---|
136 | else: |
---|
137 | form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit('clearance_locked') |
---|
138 | return form_fields |
---|
139 | |
---|
140 | def dataNotComplete(self): |
---|
141 | store = getUtility(IExtFileStore) |
---|
142 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
143 | return _('No birth certificate uploaded.') |
---|
144 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
145 | return _('No referee letter uploaded.') |
---|
146 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
147 | return _('No acceptance letter uploaded.') |
---|
148 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
149 | return _('No first sitting result uploaded.') |
---|
150 | return False |
---|
151 | |
---|
152 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
153 | """ Page to view an online payment ticket |
---|
154 | """ |
---|
155 | grok.context(INigeriaStudentOnlinePayment) |
---|
156 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) |
---|
157 | form_fields[ |
---|
158 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
159 | form_fields[ |
---|
160 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
161 | |
---|
162 | class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
163 | """ Page to add an online payment ticket |
---|
164 | """ |
---|
165 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select( |
---|
166 | 'p_category') |
---|
167 | |
---|
168 | class NigeriaOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage): |
---|
169 | """ Disable payment approval view for students. |
---|
170 | |
---|
171 | This view is used for browser tests only and |
---|
172 | has to be neutralized here! |
---|
173 | """ |
---|
174 | |
---|
175 | grok.name('fake_approve') |
---|
176 | grok.require('waeup.managePortal') |
---|
177 | |
---|
178 | def update(self): |
---|
179 | return |
---|
180 | |
---|
181 | class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
182 | """Deliver a PDF slip of the context. |
---|
183 | """ |
---|
184 | grok.context(INigeriaStudentOnlinePayment) |
---|
185 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) |
---|
186 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
187 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
188 | |
---|
189 | class StudentPassportActionButton(StudentPassportActionButton): |
---|
190 | |
---|
191 | @property |
---|
192 | def target_url(self): |
---|
193 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
194 | self.context, 'application_slip') |
---|
195 | if self.context.state != ADMITTED or slip is not None: |
---|
196 | return '' |
---|
197 | return self.view.url(self.view.context, self.target) |
---|
198 | |
---|
199 | class NigeriaStudentFilesUploadPage(StudentFilesUploadPage): |
---|
200 | """ View to upload passport picture. |
---|
201 | |
---|
202 | Students are not allowed to change the picture if they |
---|
203 | passed the regular Kofa application. |
---|
204 | """ |
---|
205 | |
---|
206 | def update(self): |
---|
207 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
208 | self.context, 'application_slip') |
---|
209 | if self.context.state != ADMITTED or slip is not None: |
---|
210 | emit_lock_message(self) |
---|
211 | return |
---|
212 | super(StudentFilesUploadPage, self).update() |
---|
213 | return |
---|