1 | ## $Id: browser.py 13380 2015-11-02 11:14:33Z 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.component import getUtility |
---|
21 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
22 | from waeup.kofa.browser.layout import UtilityView |
---|
23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from waeup.kofa.interfaces import IKofaUtils |
---|
25 | from waeup.kofa.students.interfaces import IStudentsUtils, IStudent |
---|
26 | from waeup.kofa.students.workflow import PAID, REGISTERED |
---|
27 | from waeup.kofa.students.browser import ( |
---|
28 | StartClearancePage, |
---|
29 | StudentBasePDFFormPage, |
---|
30 | CourseTicketAddFormPage, |
---|
31 | StudyLevelDisplayFormPage, |
---|
32 | ExportPDFTranscriptSlip, |
---|
33 | ExportPDFAdmissionSlip, |
---|
34 | BedTicketAddPage, |
---|
35 | StudentFilesUploadPage, |
---|
36 | ) |
---|
37 | from kofacustom.nigeria.students.browser import ( |
---|
38 | NigeriaOnlinePaymentDisplayFormPage, |
---|
39 | NigeriaOnlinePaymentAddFormPage, |
---|
40 | NigeriaExportPDFPaymentSlip, |
---|
41 | NigeriaExportPDFCourseRegistrationSlip, |
---|
42 | NigeriaExportPDFClearanceSlip, |
---|
43 | NigeriaStudentPersonalDisplayFormPage, |
---|
44 | NigeriaStudentPersonalEditFormPage, |
---|
45 | NigeriaStudentPersonalManageFormPage, |
---|
46 | NigeriaStudentClearanceEditFormPage, |
---|
47 | ) |
---|
48 | from waeup.aaue.students.interfaces import ( |
---|
49 | ICustomStudentOnlinePayment, |
---|
50 | ICustomStudentStudyLevel, |
---|
51 | ICustomStudent, |
---|
52 | ICustomStudentPersonal, |
---|
53 | ICustomStudentPersonalEdit, |
---|
54 | ICustomUGStudentClearance) |
---|
55 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
56 | |
---|
57 | class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage): |
---|
58 | """ Page to display student personal data |
---|
59 | """ |
---|
60 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
61 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
62 | form_fields['father_address'].custom_widget = BytesDisplayWidget |
---|
63 | form_fields['mother_address'].custom_widget = BytesDisplayWidget |
---|
64 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
65 | form_fields[ |
---|
66 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
67 | |
---|
68 | class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
69 | """ Page to edit personal data |
---|
70 | """ |
---|
71 | form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated') |
---|
72 | |
---|
73 | class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage): |
---|
74 | """ Page to edit personal data |
---|
75 | """ |
---|
76 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
77 | form_fields['personal_updated'].for_display = True |
---|
78 | form_fields[ |
---|
79 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
80 | |
---|
81 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
82 | """ View to edit student clearance data by student |
---|
83 | """ |
---|
84 | |
---|
85 | @property |
---|
86 | def form_fields(self): |
---|
87 | if self.context.is_postgrad: |
---|
88 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
89 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
90 | 'physical_clearance_date') |
---|
91 | else: |
---|
92 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
93 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
94 | 'physical_clearance_date') |
---|
95 | return form_fields |
---|
96 | |
---|
97 | class CustomStartClearancePage(StartClearancePage): |
---|
98 | with_ac = False |
---|
99 | |
---|
100 | @property |
---|
101 | def all_required_fields_filled(self): |
---|
102 | if not self.context.email: |
---|
103 | return _("Email address is missing."), 'edit_base' |
---|
104 | if not self.context.phone: |
---|
105 | return _("Phone number is missing."), 'edit_base' |
---|
106 | if not self.context.father_name: |
---|
107 | return _("Personal data form is not properly filled."), 'edit_personal' |
---|
108 | return |
---|
109 | |
---|
110 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
111 | """ Page to view an online payment ticket |
---|
112 | """ |
---|
113 | grok.context(ICustomStudentOnlinePayment) |
---|
114 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
115 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
116 | form_fields[ |
---|
117 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
118 | form_fields[ |
---|
119 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
120 | |
---|
121 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
122 | """ Page to add an online payment ticket |
---|
123 | """ |
---|
124 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
125 | 'p_category') |
---|
126 | |
---|
127 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
128 | """Deliver a PDF slip of the context. |
---|
129 | """ |
---|
130 | grok.context(ICustomStudentOnlinePayment) |
---|
131 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
132 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
133 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
134 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
135 | |
---|
136 | @property |
---|
137 | def note(self): |
---|
138 | text = '' |
---|
139 | if self.context.p_category == 'schoolfee' and self.context.p_level == 100: |
---|
140 | text += '\n\n Amounts include Naira 250 eTranzact transaction ' |
---|
141 | text += 'charge and Naira 2000 cost of matriculation gown.' |
---|
142 | elif self.context.p_category in ('clearance', 'schoolfee'): |
---|
143 | text += '\n\n Amounts include Naira 250 eTranzact transaction charge.' |
---|
144 | return text |
---|
145 | |
---|
146 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
147 | """ Page to display student study levels |
---|
148 | """ |
---|
149 | grok.context(ICustomStudentStudyLevel) |
---|
150 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
151 | 'total_credits', 'gpa', 'level') |
---|
152 | form_fields[ |
---|
153 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
154 | |
---|
155 | class CustomExportPDFCourseRegistrationSlip( |
---|
156 | NigeriaExportPDFCourseRegistrationSlip): |
---|
157 | """Deliver a PDF slip of the context. |
---|
158 | """ |
---|
159 | grok.context(ICustomStudentStudyLevel) |
---|
160 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
161 | 'level_session', 'level_verdict', |
---|
162 | 'validated_by', 'validation_date', 'gpa', 'level') |
---|
163 | |
---|
164 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
165 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
166 | 'department', 'current_mode', 'current_level') |
---|
167 | |
---|
168 | def update(self): |
---|
169 | if self.context.student.state != REGISTERED \ |
---|
170 | and self.context.student.current_level == self.context.level: |
---|
171 | self.flash(_('Forbidden'), type="warning") |
---|
172 | self.redirect(self.url(self.context)) |
---|
173 | |
---|
174 | @property |
---|
175 | def label(self): |
---|
176 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
177 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
178 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
179 | target_language=lang) |
---|
180 | line0 = '' |
---|
181 | if self.context.student.current_mode.endswith('_pt'): |
---|
182 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
183 | line1 = translate(_('Course Registration Slip'), |
---|
184 | 'waeup.kofa', target_language=portal_language) \ |
---|
185 | + ' %s' % level_title |
---|
186 | line2 = translate(_('Session'), |
---|
187 | 'waeup.kofa', target_language=portal_language) \ |
---|
188 | + ' %s' % self.context.getSessionString |
---|
189 | return '%s%s\n%s' % (line0, line1, line2) |
---|
190 | |
---|
191 | @property |
---|
192 | def title(self): |
---|
193 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
194 | return translate(_('Units Registered'), 'waeup.kofa', |
---|
195 | target_language=portal_language) |
---|
196 | |
---|
197 | def _signatures(self): |
---|
198 | return ( |
---|
199 | [('I have selected the course on the advise of my Head of ' |
---|
200 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
201 | [('This student has satisfied the department\'s requirements. ' |
---|
202 | 'I recommend to approve the course registration. <br>', |
---|
203 | _('Head of Department\'s Signature'), '<br>')], |
---|
204 | [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], |
---|
205 | [('', _('Director\'s Signature'))] |
---|
206 | ) |
---|
207 | |
---|
208 | def render(self): |
---|
209 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
210 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
211 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
212 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
213 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
214 | Score = translate('Score', 'waeup.kofa', target_language=portal_language) |
---|
215 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
216 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
217 | target_language=portal_language) |
---|
218 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
219 | self.request, self.omit_fields) |
---|
220 | students_utils = getUtility(IStudentsUtils) |
---|
221 | |
---|
222 | tabledata = [] |
---|
223 | tableheader = [] |
---|
224 | contenttitle = [] |
---|
225 | for i in range(1,7): |
---|
226 | tabledata.append(sorted( |
---|
227 | [value for value in self.context.values() if value.semester == i], |
---|
228 | key=lambda value: str(value.semester) + value.code)) |
---|
229 | tableheader.append([(Code,'code', 2.0), |
---|
230 | (Title,'title', 7), |
---|
231 | (Cred, 'credits', 1.5), |
---|
232 | (Score, 'score', 1.4), |
---|
233 | (Grade, 'grade', 1.4), |
---|
234 | (Signature, 'dummy', 3), |
---|
235 | ]) |
---|
236 | if len(self.label.split('\n')) == 3: |
---|
237 | topMargin = 1.9 |
---|
238 | elif len(self.label.split('\n')) == 2: |
---|
239 | topMargin = 1.7 |
---|
240 | else: |
---|
241 | topMargin = 1.5 |
---|
242 | return students_utils.renderPDF( |
---|
243 | self, 'course_registration_slip.pdf', |
---|
244 | self.context.student, studentview, |
---|
245 | tableheader=tableheader, |
---|
246 | tabledata=tabledata, |
---|
247 | signatures=self._signatures(), |
---|
248 | topMargin=topMargin, |
---|
249 | omit_fields=self.omit_fields |
---|
250 | ) |
---|
251 | |
---|
252 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
253 | """Deliver a PDF slip of the context. |
---|
254 | """ |
---|
255 | |
---|
256 | def _sigsInFooter(self): |
---|
257 | return [] |
---|
258 | |
---|
259 | def _signatures(self): |
---|
260 | return ([( |
---|
261 | 'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar <br /> ' |
---|
262 | 'Exams, Records and Data Processing Division <br /> For: Registrar')],) |
---|
263 | |
---|
264 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
265 | """Deliver a PDF Admission slip. |
---|
266 | """ |
---|
267 | |
---|
268 | @property |
---|
269 | def label(self): |
---|
270 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
271 | return translate(_('e-Admission Slip \n'), |
---|
272 | 'waeup.kofa', target_language=portal_language) \ |
---|
273 | + ' %s' % self.context.display_fullname |
---|
274 | |
---|
275 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
276 | """Deliver a PDF slip of the context. |
---|
277 | """ |
---|
278 | |
---|
279 | @property |
---|
280 | def label(self): |
---|
281 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
282 | return translate(_('Clearance Slip\n'), |
---|
283 | 'waeup.kofa', target_language=portal_language) \ |
---|
284 | + ' %s' % self.context.display_fullname |
---|
285 | |
---|
286 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
287 | """ Construct and set the matriculation number. |
---|
288 | """ |
---|
289 | grok.context(IStudent) |
---|
290 | grok.name('get_matric_number') |
---|
291 | grok.require('waeup.viewStudent') |
---|
292 | |
---|
293 | def update(self): |
---|
294 | students_utils = getUtility(IStudentsUtils) |
---|
295 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
296 | if msg: |
---|
297 | self.flash(msg, type="danger") |
---|
298 | else: |
---|
299 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
300 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
301 | self.redirect(self.url(self.context)) |
---|
302 | return |
---|
303 | |
---|
304 | def render(self): |
---|
305 | return |
---|
306 | |
---|
307 | class ExportPDFMatricNumberSlip(UtilityView, grok.View): |
---|
308 | """Deliver a PDF notification slip. |
---|
309 | """ |
---|
310 | grok.context(ICustomStudent) |
---|
311 | grok.name('matric_number_slip.pdf') |
---|
312 | grok.require('waeup.viewStudent') |
---|
313 | prefix = 'form' |
---|
314 | |
---|
315 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
316 | 'student_id', 'matric_number') |
---|
317 | omit_fields = ('date_of_birth', 'current_level') |
---|
318 | |
---|
319 | @property |
---|
320 | def label(self): |
---|
321 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
322 | return translate(_('Matriculation Number Slip\n'), |
---|
323 | 'waeup.kofa', target_language=portal_language) \ |
---|
324 | + ' %s' % self.context.display_fullname |
---|
325 | |
---|
326 | def render(self): |
---|
327 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
328 | or not self.context.matric_number: |
---|
329 | self.flash('Not allowed.', type="danger") |
---|
330 | self.redirect(self.url(self.context)) |
---|
331 | return |
---|
332 | students_utils = getUtility(IStudentsUtils) |
---|
333 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
334 | 'payments have been received and your matriculation ' + |
---|
335 | 'number generated with details as follows.') |
---|
336 | return students_utils.renderPDFAdmissionLetter(self, |
---|
337 | self.context.student, omit_fields=self.omit_fields, |
---|
338 | pre_text=pre_text, post_text='') |
---|
339 | |
---|
340 | class CustomBedTicketAddPage(BedTicketAddPage): |
---|
341 | with_ac = False |
---|
342 | |
---|
343 | class CustomStudentFilesUploadPage(StudentFilesUploadPage): |
---|
344 | """ View to upload files by student. Inherit from same class in |
---|
345 | base package, not from kofacustom.nigeria which |
---|
346 | requires that no application slip exists. |
---|
347 | """ |
---|