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