1 | ## $Id: browser.py 12391 2015-01-03 21:57: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.i18n import translate |
---|
20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
21 | from zope.component import getUtility |
---|
22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
23 | from waeup.kofa.interfaces import ( |
---|
24 | REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory) |
---|
25 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
26 | from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView |
---|
27 | from waeup.kofa.students.browser import ( |
---|
28 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
29 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage, |
---|
30 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
31 | msave, emit_lock_message, |
---|
32 | StudentActivatePage, StudentDeactivatePage) |
---|
33 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
34 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
35 | from kofacustom.nigeria.students.browser import ( |
---|
36 | NigeriaOnlinePaymentDisplayFormPage, |
---|
37 | NigeriaStudentBaseManageFormPage, |
---|
38 | NigeriaStudentClearanceEditFormPage, |
---|
39 | NigeriaOnlinePaymentAddFormPage, |
---|
40 | NigeriaExportPDFPaymentSlipPage, |
---|
41 | NigeriaExportPDFClearanceSlipPage, |
---|
42 | ) |
---|
43 | |
---|
44 | from waeup.uniben.students.interfaces import ( |
---|
45 | ICustomStudent, |
---|
46 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
47 | ICustomStudentStudyLevel, |
---|
48 | ICustomUGStudentClearance, |
---|
49 | ICustomPGStudentClearance) |
---|
50 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
51 | |
---|
52 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
53 | """ Page to view an online payment ticket |
---|
54 | """ |
---|
55 | grok.context(ICustomStudentOnlinePayment) |
---|
56 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
57 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
58 | form_fields[ |
---|
59 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
60 | form_fields[ |
---|
61 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
62 | |
---|
63 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
64 | """ View to edit student clearance data by student |
---|
65 | """ |
---|
66 | |
---|
67 | @property |
---|
68 | def form_fields(self): |
---|
69 | if self.context.is_postgrad: |
---|
70 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
71 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
72 | 'physical_clearance_date') |
---|
73 | else: |
---|
74 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
75 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
76 | 'physical_clearance_date') |
---|
77 | form_fields['date_of_birth'].for_display = True |
---|
78 | form_fields['nationality'].for_display = True |
---|
79 | form_fields['lga'].for_display = True |
---|
80 | return form_fields |
---|
81 | |
---|
82 | def dataNotComplete(self): |
---|
83 | store = getUtility(IExtFileStore) |
---|
84 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
85 | return _('No birth certificate uploaded.') |
---|
86 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
87 | return _('No guarantor/referee letter uploaded.') |
---|
88 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
89 | return _('No acceptance letter uploaded.') |
---|
90 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
91 | return _('No first sitting result uploaded.') |
---|
92 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
93 | # return _('No second sitting result uploaded.') |
---|
94 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
95 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
96 | return False |
---|
97 | |
---|
98 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
99 | """ Page to add an online payment ticket |
---|
100 | """ |
---|
101 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
102 | 'p_category') |
---|
103 | |
---|
104 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
105 | """Deliver a PDF slip of the context. |
---|
106 | """ |
---|
107 | grok.context(ICustomStudentOnlinePayment) |
---|
108 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
109 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
110 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
111 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
112 | |
---|
113 | |
---|
114 | class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): |
---|
115 | """Deliver a PDF slip of the context. |
---|
116 | """ |
---|
117 | |
---|
118 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
119 | 'phone', 'adm_code', 'email', 'date_of_birth') |
---|
120 | |
---|
121 | def render(self): |
---|
122 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
123 | self.request, self.omit_fields) |
---|
124 | students_utils = getUtility(IStudentsUtils) |
---|
125 | return students_utils.renderPDF( |
---|
126 | self, 'clearance_slip.pdf', |
---|
127 | self.context.student, studentview, signatures=self._signatures(), |
---|
128 | sigs_in_footer=self._sigsInFooter(), show_scans=False, |
---|
129 | omit_fields=self.omit_fields) |
---|
130 | |
---|
131 | |
---|
132 | class ExportClearanceInvitationSlipPage(UtilityView, grok.View): |
---|
133 | """Deliver an invitation letter to physical clearance. |
---|
134 | |
---|
135 | This form page is available only in Uniben. |
---|
136 | """ |
---|
137 | grok.context(ICustomStudent) |
---|
138 | grok.name('clearance_invitation_slip.pdf') |
---|
139 | grok.require('waeup.viewStudent') |
---|
140 | prefix = 'form' |
---|
141 | |
---|
142 | label = u'Invitation Letter for Physical Clearance' |
---|
143 | |
---|
144 | omit_fields = ( |
---|
145 | 'suspended', 'phone', 'email', |
---|
146 | 'adm_code', 'suspended_comment', |
---|
147 | 'date_of_birth', 'current_level', |
---|
148 | 'department', 'current_mode', |
---|
149 | 'entry_session', 'matric_number', 'sex') |
---|
150 | |
---|
151 | form_fields = [] |
---|
152 | |
---|
153 | @property |
---|
154 | def note(self): |
---|
155 | if self.context.physical_clearance_date: |
---|
156 | return """ |
---|
157 | <br /><br /><br /><br /><font size='12'> |
---|
158 | Dear %s, |
---|
159 | <br /><br /><br /> |
---|
160 | You are invited for your physical clearance on: |
---|
161 | <br /><br /> |
---|
162 | <strong>%s</strong>. |
---|
163 | <br /><br /> |
---|
164 | Please bring along this letter of invitation to the University Main Auditorium |
---|
165 | <br /><br /> |
---|
166 | on your clearance date. |
---|
167 | <br /><br /><br /> |
---|
168 | Signed, |
---|
169 | <br /><br /> |
---|
170 | The Registrar<br /> |
---|
171 | </font> |
---|
172 | |
---|
173 | """ % (self.context.display_fullname, self.context.physical_clearance_date) |
---|
174 | return |
---|
175 | |
---|
176 | |
---|
177 | def update(self): |
---|
178 | if self.context.student.state != REQUESTED \ |
---|
179 | or not self.context.student.physical_clearance_date: |
---|
180 | self.flash(_('Forbidden'), type="warning") |
---|
181 | self.redirect(self.url(self.context)) |
---|
182 | |
---|
183 | def render(self): |
---|
184 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
185 | self.request, self.omit_fields) |
---|
186 | students_utils = getUtility(IStudentsUtils) |
---|
187 | return students_utils.renderPDF( |
---|
188 | self, 'clearance_invitation_slip', |
---|
189 | self.context.student, studentview, |
---|
190 | omit_fields=self.omit_fields, |
---|
191 | note=self.note) |
---|
192 | |
---|
193 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
194 | """ Page to edit the student study course data by clearance officers. |
---|
195 | |
---|
196 | This form page is available only in Uniben. |
---|
197 | """ |
---|
198 | grok.context(ICustomStudentStudyCourse) |
---|
199 | grok.name('edit_level') |
---|
200 | grok.require('waeup.clearStudent') |
---|
201 | label = _('Edit current level') |
---|
202 | pnav = 4 |
---|
203 | form_fields = grok.AutoFields( |
---|
204 | ICustomStudentStudyCourse).select('current_level') |
---|
205 | |
---|
206 | def update(self): |
---|
207 | if not (self.context.is_current and |
---|
208 | self.context.student.state == REQUESTED): |
---|
209 | emit_lock_message(self) |
---|
210 | return |
---|
211 | super(StudyCourseCOEditFormPage, self).update() |
---|
212 | return |
---|
213 | |
---|
214 | @action(_('Save'), style='primary') |
---|
215 | def save(self, **data): |
---|
216 | try: |
---|
217 | msave(self, **data) |
---|
218 | except ConstraintNotSatisfied: |
---|
219 | # The selected level might not exist in certificate |
---|
220 | self.flash(_('Current level not available for certificate.')) |
---|
221 | return |
---|
222 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
223 | return |
---|
224 | |
---|
225 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
226 | """ Page to edit the student study level data by students. |
---|
227 | |
---|
228 | """ |
---|
229 | grok.template('studyleveleditpage') |
---|
230 | |
---|
231 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
232 | """ Page to display student study levels |
---|
233 | """ |
---|
234 | grok.template('studylevelpage') |
---|
235 | |
---|
236 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
237 | ExportPDFCourseRegistrationSlipPage): |
---|
238 | """Deliver a PDF slip of the context. |
---|
239 | """ |
---|
240 | |
---|
241 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
242 | 'level_verdict', 'gpa') |
---|
243 | |
---|
244 | @property |
---|
245 | def tabletitle(self): |
---|
246 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
247 | tabletitle = [] |
---|
248 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
249 | target_language=portal_language)) |
---|
250 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
251 | target_language=portal_language)) |
---|
252 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
253 | target_language=portal_language)) |
---|
254 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
255 | target_language=portal_language)) |
---|
256 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
257 | target_language=portal_language)) |
---|
258 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
259 | target_language=portal_language)) |
---|
260 | return tabletitle |
---|
261 | |
---|
262 | def render(self): |
---|
263 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
264 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
265 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
266 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
267 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
268 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
269 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
270 | self.request, self.omit_fields) |
---|
271 | students_utils = getUtility(IStudentsUtils) |
---|
272 | |
---|
273 | tabledata = [] |
---|
274 | tableheader = [] |
---|
275 | contenttitle = [] |
---|
276 | for i in range(1,7): |
---|
277 | tabledata.append(sorted( |
---|
278 | [value for value in self.context.values() if value.semester == i], |
---|
279 | key=lambda value: str(value.semester) + value.code)) |
---|
280 | tableheader.append([(Code,'code', 2.5), |
---|
281 | (Title,'title', 5), |
---|
282 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
283 | (Cred, 'credits', 1.5), |
---|
284 | ]) |
---|
285 | return students_utils.renderPDF( |
---|
286 | self, 'course_registration_slip.pdf', |
---|
287 | self.context.student, studentview, |
---|
288 | tableheader=tableheader, |
---|
289 | tabledata=tabledata, |
---|
290 | omit_fields=self.omit_fields |
---|
291 | ) |
---|
292 | |
---|
293 | class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): |
---|
294 | """Deliver a PDF slip of the context. |
---|
295 | """ |
---|
296 | |
---|
297 | grok.name('course_result_slip.pdf') |
---|
298 | |
---|
299 | @property |
---|
300 | def tabletitle(self): |
---|
301 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
302 | tabletitle = [] |
---|
303 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
304 | target_language=portal_language)) |
---|
305 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
306 | target_language=portal_language)) |
---|
307 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
308 | target_language=portal_language)) |
---|
309 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
310 | target_language=portal_language)) |
---|
311 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
312 | target_language=portal_language)) |
---|
313 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
314 | target_language=portal_language)) |
---|
315 | return tabletitle |
---|
316 | |
---|
317 | @property |
---|
318 | def label(self): |
---|
319 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
320 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
321 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
322 | target_language=lang) |
---|
323 | return translate(_('Course Result Slip'), |
---|
324 | 'waeup.uniben', target_language=portal_language) \ |
---|
325 | + ' %s' % level_title |
---|
326 | |
---|
327 | def render(self): |
---|
328 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
329 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
330 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
331 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
332 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
333 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
334 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
335 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
336 | self.request, self.omit_fields) |
---|
337 | students_utils = getUtility(IStudentsUtils) |
---|
338 | |
---|
339 | tabledata = [] |
---|
340 | tableheader = [] |
---|
341 | contenttitle = [] |
---|
342 | for i in range(1,7): |
---|
343 | tabledata.append(sorted( |
---|
344 | [value for value in self.context.values() if value.semester == i], |
---|
345 | key=lambda value: str(value.semester) + value.code)) |
---|
346 | tableheader.append([(Code,'code', 2.5), |
---|
347 | (Title,'title', 5), |
---|
348 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
349 | (Cred, 'credits', 1.5), |
---|
350 | (Grade, 'grade', 1.5), |
---|
351 | ]) |
---|
352 | return students_utils.renderPDF( |
---|
353 | self, 'course_registration_slip.pdf', |
---|
354 | self.context.student, studentview, |
---|
355 | tableheader=tableheader, |
---|
356 | tabledata=tabledata, |
---|
357 | omit_fields=self.omit_fields |
---|
358 | ) |
---|
359 | |
---|
360 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
361 | """ Page to display course tickets |
---|
362 | """ |
---|
363 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
364 | |
---|
365 | class CustomStudentActivatePage(StudentActivatePage): |
---|
366 | """ Activate student account |
---|
367 | """ |
---|
368 | |
---|
369 | def update(self): |
---|
370 | self.context.suspended = False |
---|
371 | self.context.writeLogMessage(self, 'account activated') |
---|
372 | history = IObjectHistory(self.context) |
---|
373 | history.addMessage('Student account activated', user='undisclosed') |
---|
374 | self.flash(_('Student account has been activated.')) |
---|
375 | self.redirect(self.url(self.context)) |
---|
376 | return |
---|
377 | |
---|
378 | class CustomStudentDeactivatePage(StudentDeactivatePage): |
---|
379 | """ Deactivate student account |
---|
380 | """ |
---|
381 | def update(self): |
---|
382 | self.context.suspended = True |
---|
383 | self.context.writeLogMessage(self, 'account deactivated') |
---|
384 | history = IObjectHistory(self.context) |
---|
385 | history.addMessage('Student account deactivated', user='undisclosed') |
---|
386 | self.flash(_('Student account has been deactivated.')) |
---|
387 | self.redirect(self.url(self.context)) |
---|
388 | return |
---|