source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py @ 18262

Last change on this file since 18262 was 18262, checked in by Henrik Bettermann, 7 months ago

Customize attendance sheet.

  • Property svn:keywords set to Id
File size: 21.1 KB
Line 
1## $Id: browser.py 18262 2026-05-05 13:18:37Z 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##
18import grok
19import os
20import textwrap
21from zope.i18n import translate
22from zope.component import getUtility, queryUtility
23from zope.catalog.interfaces import ICatalog
24from zope.security import checkPermission
25from hurry.workflow.interfaces import IWorkflowInfo
26from waeup.kofa.interfaces import ADMITTED, VALIDATED, IKofaUtils
27from waeup.kofa.interfaces import MessageFactory as _
28from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
29from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
30from waeup.kofa.students.browser import (
31    StartClearancePage,
32    ExportPDFAdmissionSlip,
33    PaymentsManageFormPage,
34    OnlinePaymentApproveView,
35    CourseTicketDisplayFormPage,
36    CourseTicketManageFormPage,
37    StudentBasePDFFormPage,
38    StudyLevelDisplayFormPage,
39    StudyLevelManageFormPage,
40    StudyLevelEditFormPage,
41    ExportAttendanceSlip)
42from kofacustom.nigeria.students.browser import (
43    NigeriaOnlinePaymentDisplayFormPage,
44    NigeriaOnlinePaymentAddFormPage,
45    NigeriaExportPDFPaymentSlip,
46    NigeriaStudentClearanceDisplayFormPage,
47    NigeriaStudentClearanceEditFormPage,
48    NigeriaStudentClearanceManageFormPage,
49    NigeriaExportPDFClearanceSlip,
50    NigeriaExportPDFCourseRegistrationSlip,
51    NigeriaBedTicketAddPage,
52    NigeriaAccommodationManageFormPage,
53    NigeriaAccommodationDisplayFormPage,
54    )
55
56from waeup.fceokene.students.interfaces import (
57    ICustomStudentOnlinePayment,
58    ICustomUGStudentClearance,
59    ICustomPGStudentClearance,
60    ICustomStudentStudyLevel)
61
62class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
63    """Deliver a PDF Admission slip.
64    """
65
66    @property
67    def label(self):
68        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
69        line0 = ''
70        if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP':
71            line0 = 'IN AFFILIATION WITH UNIVERSITY OF IBADAN\n'
72        line1 = translate(_('Admission Letter of'),
73            'waeup.kofa', target_language=portal_language) \
74            + ' %s' % self.context.display_fullname
75        return '%s%s' % (line0, line1)
76
77    @property
78    def _post_text(self):
79        return """You should note the following as conditions for admission:
80
811. At the point of registration, you will be required to present the originals of your
82   certificate(s), Jamb Original Result, a Birth Certificate or a Declaration of
83   Age Certificate and Evidence of Citizenship Certificate.
84
852. Please note that the name by which you are hereby admitted and by which you will
86   be registered is the one which will appear on any certificate that the
87   Federal College of Education, Okene may issue to you on successful completion of
88   your programme except there was a change of name by sworn affidavit or
89   marriage certificate in addition to newspaper publication.
90
913. You are hereby informed that all fees must be paid at the beginning of the
92   academic session. The current school fees can be obtained from the College website.
93
944. You will present at the time of registration the Medical Certificate of Fitness
95   from the Federal College of Education, Okene Medical Centre.
96
975. Students shall be given accommodations on first come, first serve basis.
98
996. The offer is not transferable to another session.
100
1017. You will sign a declaration of good conduct except by deferment on your
102   arrival at the College.
103
104Accept my congratulations. Yours faithfully
105
106Ajoge E, A
107Deputy Registrar (Admissions)
108For: Registrar
109"""
110
111    def render(self):
112        students_utils = getUtility(IStudentsUtils)
113        letterhead_path = os.path.join(
114            os.path.dirname(__file__), 'static', 'letterhead_admission.jpg')
115        topMargin=1.8
116        if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP':
117            letterhead_path = None
118            topMargin=1.3
119        return students_utils.renderPDFAdmissionLetter(self,
120            self.context.student, omit_fields=self.omit_fields,
121            letterhead_path=letterhead_path,
122            topMargin=topMargin,
123            post_text=self._post_text)
124
125class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
126    """ Page to view an online payment ticket
127    """
128    grok.context(ICustomStudentOnlinePayment)
129    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
130        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
131    form_fields[
132        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
133    form_fields[
134        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
135
136class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
137    """ Page to add an online payment ticket
138    """
139    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
140        'p_combi')
141
142class OnlinePaymentApproveView(OnlinePaymentApproveView):
143    grok.require('waeup.manageStudent')
144
145class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
146    """Deliver a PDF slip of the context.
147    """
148    grok.context(ICustomStudentOnlinePayment)
149    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
150        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
151    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
152    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
153
154class CustomStartClearancePage(StartClearancePage):
155
156    @property
157    def with_ac(self):
158        mode = getattr(self.context, 'current_mode', None)
159        if mode and mode.startswith('ug'):
160            return True
161        return False
162
163class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage):
164    """ Page to display student clearance data
165    """
166
167    @property
168    def form_fields(self):
169        if self.context.is_postgrad:
170            form_fields = grok.AutoFields(
171                ICustomPGStudentClearance).omit('clearance_locked')
172        else:
173            form_fields = grok.AutoFields(
174                ICustomUGStudentClearance).omit('clearance_locked')
175        if not getattr(self.context, 'officer_comment'):
176            form_fields = form_fields.omit('officer_comment')
177        else:
178            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
179        return form_fields
180
181
182class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage):
183    """ Page to edit student clearance data
184    """
185
186    @property
187    def form_fields(self):
188        if self.context.is_postgrad:
189            form_fields = grok.AutoFields(
190                ICustomPGStudentClearance).omit('clr_code')
191        else:
192            form_fields = grok.AutoFields(
193                ICustomUGStudentClearance).omit('clr_code')
194        return form_fields
195
196
197class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
198    """Deliver a PDF slip of the context.
199    """
200
201    @property
202    def form_fields(self):
203        if self.context.is_postgrad:
204            form_fields = grok.AutoFields(
205                ICustomPGStudentClearance).omit('clearance_locked')
206        else:
207            form_fields = grok.AutoFields(
208                ICustomUGStudentClearance).omit('clearance_locked')
209        if not getattr(self.context, 'officer_comment'):
210            form_fields = form_fields.omit('officer_comment')
211        return form_fields
212
213    @property
214    def label(self):
215        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
216
217        line0 = ''
218        if self.context.student.current_mode.startswith('ug'):
219            line0 = 'Directorate of Undergraduate Programme\n'
220        line1 = translate(_('Clearance Slip of'),
221            'waeup.kofa', target_language=portal_language) \
222            + ' %s' % self.context.display_fullname
223        return '%s%s' % (line0, line1)
224
225
226class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
227    """ View to edit student clearance data by student
228    """
229
230    def dataNotComplete(self):
231        return False
232
233    @property
234    def form_fields(self):
235        if self.context.is_postgrad:
236            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
237            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
238            'physical_clearance_date')
239        else:
240            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
241            'clearance_locked', 'clr_code', 'officer_comment',
242            'physical_clearance_date')
243        return form_fields
244
245class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
246    """ Page to add an online payment ticket
247    """
248    buttonname = _('Create bed ticket')
249    notice = ''
250    with_ac = False
251    with_bedselection = True
252
253class CustomExportPDFCourseRegistrationSlip(
254    NigeriaExportPDFCourseRegistrationSlip):
255    """Deliver a PDF slip of the context.
256    """
257    grok.context(ICustomStudentStudyLevel)
258    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
259        'level', 'level_verdict', 'validated_by', 'transcript_remark', 'gpa')
260    form_fields[
261        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
262    omit_fields = ('password', 'suspended', 'suspended_comment',
263        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
264        'flash_notice', 'parents_email', 'entry_session', 'password_updated')
265
266    def render(self):
267        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
268        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
269        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
270        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
271        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
272        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
273        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
274        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
275        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
276        CC = translate(_('Cat.'), target_language=portal_language)
277        studentview = StudentBasePDFFormPage(self.context.student,
278            self.request, self.omit_fields)
279        students_utils = getUtility(IStudentsUtils)
280
281        tabledata = []
282        tableheader = []
283        for i in range(1,7):
284            tabledata.append(sorted(
285                [value for value in self.context.values() if value.semester == i],
286                key=lambda value: str(value.semester) + value.code))
287            tableheader.append([(Code,'code', 2.5),
288                             (Title,'title', 7),
289                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
290                             (Cred, 'credits', 1.5),
291                             (CC, 'course_category', 1.5),
292                             #(Mand, 'mandatory', 1.5),
293                             #(Score, 'score', 1.5),
294                             #(Grade, 'grade', 1.5),
295                             #('Auto', 'automatic', 1.5)
296                             ])
297        return students_utils.renderPDF(
298            self, 'course_registration_slip_%s.pdf' % self.context.student.student_id,
299            self.context.student, studentview,
300            tableheader=tableheader,
301            tabledata=tabledata,
302            omit_fields=self.omit_fields,
303            signatures=self._signatures(),
304            sigs_in_footer=self._sigsInFooter(),
305            )
306
307class ExportPDFCourseResultSlip(CustomExportPDFCourseRegistrationSlip):
308    """Deliver a PDF slip of the context.
309    """
310
311    grok.name('course_result_slip.pdf')
312
313    @property
314    def label(self):
315        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
316        lang = self.request.cookies.get('kofa.language', portal_language)
317        level_title = translate(self.context.level_title, 'waeup.kofa',
318            target_language=lang)
319        return translate(_('Course Result Slip'),
320            'waeup.uniben', target_language=portal_language) \
321            + ' %s' % level_title
322
323    def render(self):
324        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
325        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
326        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
327        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
328        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
329        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
330        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
331        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
332        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
333        CC = translate(_('Cat.'), target_language=portal_language)
334        studentview = StudentBasePDFFormPage(self.context.student,
335            self.request, self.omit_fields)
336        students_utils = getUtility(IStudentsUtils)
337
338        tabledata = []
339        tableheader = []
340        for i in range(1,7):
341            tabledata.append(sorted(
342                [value for value in self.context.values() if value.semester == i],
343                key=lambda value: str(value.semester) + value.code))
344            tableheader.append([(Code,'code', 2.5),
345                             (Title,'title', 5),
346                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
347                             (Cred, 'credits', 1.5),
348                             (CC, 'course_category', 1.5),
349                             #(Mand, 'mandatory', 1.5),
350                             (Score, 'score', 1.5),
351                             (Grade, 'grade', 1.5),
352                             #('Auto', 'automatic', 1.5)
353                             ])
354        return students_utils.renderPDF(
355            self, 'course_result_slip_%s.pdf' % self.context.student.student_id,
356            self.context.student, studentview,
357            tableheader=tableheader,
358            tabledata=tabledata,
359            omit_fields=self.omit_fields,
360            signatures=self._signatures(),
361            sigs_in_footer=self._sigsInFooter(),
362            )
363
364
365class ExportPDFExaminationClearanceSlip1(CustomExportPDFCourseRegistrationSlip):
366    """Deliver a PDF slip of the context.
367    """
368    grok.name('examination_clearance_slip_1.pdf')
369    form_fields = None
370    omit_fields = (
371        'password', 'suspended', 'phone', 'date_of_birth',
372        'parents_email', 'current_mode', 'entry_session',
373        'adm_code', 'sex', 'suspended_comment',
374        'flash_notice', 'password_updated', 'current_level')
375    semester = 1
376    tabletitle =  ['', '', '']
377
378    @property
379    def label(self):
380        return '%s First Semester Examination Clearance' % self.context.level_session
381
382    @property
383    def title(self):
384        return ''
385
386    def update(self):
387        if self.context.student.state != VALIDATED \
388            or self.context.student.current_level != self.context.level:
389            self.flash(_('Forbidden'), type="warning")
390            self.redirect(self.url(self.context))
391
392    def render(self):
393        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
394        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
395        studentview = StudentBasePDFFormPage(self.context.student,
396            self.request, self.omit_fields)
397        students_utils = getUtility(IStudentsUtils)
398
399        tabledata = []
400        tableheader = []
401        for i in range(1,7):
402            tabledata.append(sorted(
403                [value for value in self.context.values() if i == self.semester == value.semester],
404                key=lambda value: value.code))
405            tableheader.append([(Code,'code', 2.5),
406                             ('Invigilator\'s Name','inv', 8),
407                             ('Signature and Date','sig', 7),
408                             ])
409        return students_utils.renderPDF(
410            self, 'examination_clearance_slip_%s.pdf' % self.semester,
411            self.context.student, studentview,
412            tableheader=tableheader,
413            tabledata=tabledata,
414            omit_fields=self.omit_fields,
415            topMargin=1.3
416            )
417
418class ExportPDFExaminationClearanceSlip2(ExportPDFExaminationClearanceSlip1):
419    """Deliver a PDF slip of the context.
420    """
421    grok.name('examination_clearance_slip_2.pdf')
422    semester = 2
423
424    @property
425    def label(self):
426        return '%s Second Semester Examination Clearance' % self.context.level_session
427
428class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
429    """ Page to display student study levels
430    """
431    grok.context(ICustomStudentStudyLevel)
432    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level')
433    form_fields[
434        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
435
436class CustomStudyLevelManageFormPage(StudyLevelManageFormPage):
437    """ Page to edit the student study level data
438    """
439
440class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
441    """ Page to edit the student study level data by students
442    """
443
444class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
445    """ Page to display course tickets
446    """
447    form_fields = grok.AutoFields(ICourseTicket).omit(
448        'ticket_session')
449
450class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
451    """ Page to manage course tickets
452    """
453    form_fields = grok.AutoFields(ICourseTicket)
454    form_fields['title'].for_display = True
455    form_fields['fcode'].for_display = True
456    form_fields['dcode'].for_display = True
457    form_fields['semester'].for_display = True
458    form_fields['passmark'].for_display = True
459    form_fields['credits'].for_display = True
460    form_fields['mandatory'].for_display = False
461    form_fields['automatic'].for_display = True
462    form_fields['carry_over'].for_display = True
463    form_fields['ticket_session'].for_display = True
464
465class CustomPaymentsManageFormPage(PaymentsManageFormPage):
466    """ Page to manage the student payments. This manage form page is for
467    both students and students officers. FCEOkene does not allow students
468    to remove any payment ticket.
469    """
470    @property
471    def manage_payments_allowed(self):
472        return checkPermission('waeup.manageStudent', self.context)
473
474class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
475    """ Page to view bed tickets.
476    """
477    with_hostel_selection = True
478
479class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
480    """ Page to manage bed tickets.
481    This manage form page is for both students and students officers.
482    """
483    with_hostel_selection = True
484
485class CustomExportAttendanceSlip(ExportAttendanceSlip):
486    """Deliver a PDF slip of course tickets in attendance sheet format.
487    """
488
489    def data(self, session):
490        cat = queryUtility(ICatalog, name='coursetickets_catalog')
491        # Attention: Also tickets of previous studycourses are found
492        coursetickets = cat.searchResults(
493            session=(session, session),
494            code=(self.context.code, self.context.code)
495            )
496        header = [[_('S/N'),
497                   _('Matric No.'),
498                   _('Name'),
499                   _('Level'),
500                  #_('Course of\nStudies'),
501                   _('Booklet\nNo.'),
502                  #_('Venue'),
503                  #_('Time'),
504                   _('Sign in'),
505                   _('Sign out'),
506                   ],]
507        tickets = []
508        sn = 1
509        ctlist = sorted(list(coursetickets),
510                        key=lambda value: str(value.student.faccode) +
511                                          str(value.student.depcode) +
512                                          str(value.student.certcode) +
513                                          str(value.student.matric_number))
514        # In AAUE only editable appear on the attendance sheet. Hopefully
515        # this holds for other universities too.
516        editable_tickets = [ticket for ticket in ctlist
517            if ticket.editable_by_lecturer]
518        for ticket in editable_tickets:
519            name = textwrap.fill(ticket.student.display_fullname, 30)
520            row = [sn,
521                  ticket.student.matric_number,
522                  name,
523                  ticket.level,
524                  #ticket.student.certcode,
525                  10 * ' ',
526                  #10 * ' ',
527                  #10 * ' ',
528                  20 * ' ',
529                  20 * ' ',
530                  ]
531            tickets.append(row)
532            sn += 1
533        return header + tickets, None
Note: See TracBrowser for help on using the repository browser.