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