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