1 | ## $Id: browser.py 8891 2012-07-03 17:20:29Z uli $ |
---|
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, 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 NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
79 | """ Page to display student clearance data |
---|
80 | """ |
---|
81 | |
---|
82 | @property |
---|
83 | def form_fields(self): |
---|
84 | cm = getattr(self.context,'current_mode', None) |
---|
85 | if cm is not None and cm.startswith('pg'): |
---|
86 | form_fields = grok.AutoFields( |
---|
87 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
88 | else: |
---|
89 | form_fields = grok.AutoFields( |
---|
90 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
91 | return form_fields |
---|
92 | |
---|
93 | class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
94 | """Deliver a PDF slip of the context. |
---|
95 | """ |
---|
96 | |
---|
97 | @property |
---|
98 | def form_fields(self): |
---|
99 | cm = getattr(self.context,'current_mode', None) |
---|
100 | if cm is not None and cm.startswith('pg'): |
---|
101 | form_fields = grok.AutoFields( |
---|
102 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
103 | else: |
---|
104 | form_fields = grok.AutoFields( |
---|
105 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
106 | return form_fields |
---|
107 | |
---|
108 | class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
109 | """ Page to edit student clearance data |
---|
110 | """ |
---|
111 | |
---|
112 | @property |
---|
113 | def form_fields(self): |
---|
114 | cm = getattr(self.context,'current_mode', None) |
---|
115 | if cm is not None and cm.startswith('pg'): |
---|
116 | form_fields = grok.AutoFields(INigeriaPGStudentClearance) |
---|
117 | else: |
---|
118 | form_fields = grok.AutoFields(INigeriaUGStudentClearance) |
---|
119 | return form_fields |
---|
120 | |
---|
121 | class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
122 | """ View to edit student clearance data by student |
---|
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).omit('clearance_locked') |
---|
130 | else: |
---|
131 | form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit('clearance_locked') |
---|
132 | return form_fields |
---|
133 | |
---|
134 | def dataNotComplete(self): |
---|
135 | store = getUtility(IExtFileStore) |
---|
136 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
137 | return _('No birth certificate uploaded.') |
---|
138 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
139 | return _('No referee letter uploaded.') |
---|
140 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
141 | return _('No acceptance letter uploaded.') |
---|
142 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
143 | return _('No first sitting result uploaded.') |
---|
144 | return False |
---|
145 | |
---|
146 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
147 | """ Page to view an online payment ticket |
---|
148 | """ |
---|
149 | grok.context(INigeriaStudentOnlinePayment) |
---|
150 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) |
---|
151 | form_fields[ |
---|
152 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
153 | form_fields[ |
---|
154 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
155 | |
---|
156 | class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
157 | """ Page to add an online payment ticket |
---|
158 | """ |
---|
159 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select( |
---|
160 | 'p_category') |
---|
161 | |
---|
162 | class NigeriaOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage): |
---|
163 | """ Disable payment approval view for students. |
---|
164 | |
---|
165 | This view is used for browser tests only and |
---|
166 | has to be neutralized here! |
---|
167 | """ |
---|
168 | |
---|
169 | grok.name('fake_approve') |
---|
170 | grok.require('waeup.managePortal') |
---|
171 | |
---|
172 | def update(self): |
---|
173 | return |
---|
174 | |
---|
175 | class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
176 | """Deliver a PDF slip of the context. |
---|
177 | """ |
---|
178 | grok.context(INigeriaStudentOnlinePayment) |
---|
179 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) |
---|
180 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
181 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
182 | |
---|
183 | class StudentPassportActionButton(StudentPassportActionButton): |
---|
184 | |
---|
185 | @property |
---|
186 | def target_url(self): |
---|
187 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
188 | self.context, 'application_slip') |
---|
189 | if self.context.state != ADMITTED or slip is not None: |
---|
190 | return '' |
---|
191 | return self.view.url(self.view.context, self.target) |
---|
192 | |
---|
193 | class NigeriaStudentFilesUploadPage(StudentFilesUploadPage): |
---|
194 | """ View to upload passport picture. |
---|
195 | |
---|
196 | Students are not allowed to change the picture if they |
---|
197 | passed the regular Kofa application. |
---|
198 | """ |
---|
199 | |
---|
200 | def update(self): |
---|
201 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
202 | self.context, 'application_slip') |
---|
203 | if self.context.state != ADMITTED or slip is not None: |
---|
204 | emit_lock_message(self) |
---|
205 | return |
---|
206 | super(StudentFilesUploadPage, self).update() |
---|
207 | return |
---|