source: main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py @ 16017

Last change on this file since 16017 was 15975, checked in by Henrik Bettermann, 5 years ago

Adjust to changes in base package.

  • Property svn:keywords set to Id
File size: 27.4 KB
RevLine 
[8911]1## $Id: browser.py 15975 2020-01-31 21:52:05Z 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
19from zope.i18n import translate
[13719]20from zope.security import checkPermission
[9210]21from zope.schema.interfaces import ConstraintNotSatisfied
[12856]22from zope.formlib.textwidgets import BytesDisplayWidget
[9380]23from zope.component import getUtility
[9281]24from hurry.workflow.interfaces import IWorkflowInfo
[11069]25from waeup.kofa.interfaces import (
26    REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory)
[8911]27from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[12121]28from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView
[9205]29from waeup.kofa.students.browser import (
[15352]30    StudentBaseEditFormPage,
[9686]31    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
[13063]32    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
[10025]33    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
[11069]34    msave, emit_lock_message,
[13063]35    StudentActivateView, StudentDeactivateView,
[13719]36    ExportPDFTranscriptSlip,
[15574]37    PaymentsManageFormPage,
38    StartClearancePage)
[12845]39from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
40    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
[15164]41    GRADUATED, FORBIDDEN_POSTGRAD_TRANS)
[9686]42from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
[9251]43from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
[8911]44from kofacustom.nigeria.students.browser import (
45    NigeriaOnlinePaymentDisplayFormPage,
[9251]46    NigeriaStudentBaseManageFormPage,
[9380]47    NigeriaStudentClearanceEditFormPage,
[8911]48    NigeriaOnlinePaymentAddFormPage,
[13063]49    NigeriaExportPDFPaymentSlip,
50    NigeriaExportPDFClearanceSlip,
[13297]51    NigeriaExportPDFBedTicketSlip,
[12856]52    NigeriaStudentPersonalDisplayFormPage,
[13085]53    NigeriaStudentPersonalManageFormPage,
[15267]54    NigeriaStudentPersonalEditFormPage,
[15371]55    NigeriaAccommodationManageFormPage,
[15975]56    NigeriaAccommodationDisplayFormPage,
[15371]57    NigeriaStudentBaseDisplayFormPage,
[9281]58    )
[8911]59
[9210]60from waeup.uniben.students.interfaces import (
[12121]61    ICustomStudent,
[15352]62    ICustomStudentBase,
[12856]63    ICustomStudentOnlinePayment,
64    ICustomStudentStudyCourse,
[11552]65    ICustomStudentStudyLevel,
66    ICustomUGStudentClearance,
[12856]67    ICustomPGStudentClearance,
[13085]68    ICustomStudentPersonal,
69    ICustomStudentPersonalEdit)
[9210]70from waeup.uniben.interfaces import MessageFactory as _
[8911]71
[15371]72class CustomStudentBaseDisplayFormPage(NigeriaStudentBaseDisplayFormPage):
73    """ Page to display student base data
74    """
75    form_fields = grok.AutoFields(ICustomStudentBase).omit(
76        'password', 'suspended', 'suspended_comment',
77        'flash_notice', 'provisionally_cleared')
78    form_fields[
79        'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
80
81#class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
82#    """ View to manage student base data
83#    """
84#    form_fields = grok.AutoFields(ICustomStudentBase).omit(
85#        'student_id', 'adm_code', 'suspended',
86#        'financially_cleared_by', 'financial_clearance_date')
87
[8911]88class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
89    """ Page to view an online payment ticket
90    """
91    grok.context(ICustomStudentOnlinePayment)
[9775]92    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9993]93        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]94    form_fields[
95        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
96    form_fields[
97        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
98
[15574]99class CustomStartClearancePage(StartClearancePage):
100
101    @property
102    def with_ac(self):
103        if self.context.faccode == 'DCOEM':
104            return False
105        return True
106
[9380]107class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
108    """ View to edit student clearance data by student
109    """
110
[11552]111    @property
112    def form_fields(self):
113        if self.context.is_postgrad:
114            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
[12391]115            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
116            'physical_clearance_date')
[11552]117        else:
118            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
[12391]119            'clearance_locked', 'clr_code', 'officer_comment',
120            'physical_clearance_date')
[11552]121            form_fields['date_of_birth'].for_display = True
122            form_fields['nationality'].for_display = True
123            form_fields['lga'].for_display = True
124        return form_fields
125
[15666]126    def dataNotComplete(self):
[9380]127        store = getUtility(IExtFileStore)
128        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
129            return _('No birth certificate uploaded.')
130        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
131            return _('No guarantor/referee letter uploaded.')
132        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
133            return _('No acceptance letter uploaded.')
134        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
135            return _('No first sitting result uploaded.')
[9395]136        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
137        #    return _('No second sitting result uploaded.')
[9380]138        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
[9848]139            return _('No affidavit of non-membership of secret cults uploaded.')
[9380]140        return False
141
[8911]142class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
143    """ Page to add an online payment ticket
144    """
145    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
[15666]146        'p_combi')
[8911]147
[13063]148class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
[8911]149    """Deliver a PDF slip of the context.
150    """
151    grok.context(ICustomStudentOnlinePayment)
[9775]152    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[15688]153        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
[8911]154    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9205]155    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
156
157
[13063]158class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
[9551]159    """Deliver a PDF slip of the context.
160    """
161
[13303]162    @property
163    def omit_fields(self):
164        omit_fields = ('password', 'suspended', 'suspended_comment',
[13717]165                       'phone', 'adm_code', 'email', 'date_of_birth',
166                       'flash_notice')
[14902]167        if self.context.is_jupeb:
[13303]168            omit_fields += ('faculty', 'department')
169        return omit_fields
[11537]170
[13299]171    @property
172    def label(self):
173        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[13300]174        line0 = ''
[14902]175        if self.context.is_jupeb:
[13335]176            line0 = 'Joint Universities Preliminary Examinations Board (JUPEB)\n'
[13300]177        line1 = translate(_('Clearance Slip of'),
[13299]178            'waeup.kofa', target_language=portal_language) \
179            + ' %s' % self.context.display_fullname
[13335]180        return '%s%s' % (line0, line1)
[13299]181
[12846]182    def _sigsInFooter(self):
[12845]183        isStudent = getattr(
184            self.request.principal, 'user_type', None) == 'student'
[12852]185        if not isStudent and self.context.state in (CLEARED, RETURNING):
[12846]186            return (_('Date, Student Signature'),
187                    _('Date, Clearance Officer Signature'),
188                    )
189        return ()
[12845]190
[9551]191    def render(self):
192        studentview = StudentBasePDFFormPage(self.context.student,
193            self.request, self.omit_fields)
194        students_utils = getUtility(IStudentsUtils)
195        return students_utils.renderPDF(
196            self, 'clearance_slip.pdf',
197            self.context.student, studentview, signatures=self._signatures(),
[10271]198            sigs_in_footer=self._sigsInFooter(), show_scans=False,
199            omit_fields=self.omit_fields)
[9551]200
[12121]201
[13063]202class ExportClearanceInvitationSlip(UtilityView, grok.View):
[12121]203    """Deliver an invitation letter to physical clearance.
204
205    This form page is available only in Uniben.
206    """
207    grok.context(ICustomStudent)
208    grok.name('clearance_invitation_slip.pdf')
209    grok.require('waeup.viewStudent')
210    prefix = 'form'
211
[12263]212    label = u'Invitation Letter for Physical Clearance'
[12121]213
214    omit_fields = (
215        'suspended', 'phone', 'email',
216        'adm_code', 'suspended_comment',
217        'date_of_birth', 'current_level',
[12150]218        'department', 'current_mode',
[13717]219        'entry_session', 'matric_number', 'sex',
220        'flash_notice')
[12121]221
222    form_fields = []
223
224    @property
225    def note(self):
226        if self.context.physical_clearance_date:
227            return """
[12147]228<br /><br /><br /><br /><font size='12'>
229Dear %s,
230<br /><br /><br />
[12264]231You are invited for your physical clearance on:
[12121]232<br /><br />
[12264]233<strong>%s</strong>.
234<br /><br />
[12265]235Please bring along this letter of invitation to the University Main Auditorium
[12147]236<br /><br />
[12263]237on your clearance date.
[12147]238<br /><br /><br />
[12263]239Signed,
[12147]240<br /><br />
241The Registrar<br />
[12121]242</font>
243
[12147]244""" % (self.context.display_fullname, self.context.physical_clearance_date)
[12121]245        return
246
[12122]247
248    def update(self):
249        if self.context.student.state != REQUESTED \
250            or not  self.context.student.physical_clearance_date:
251            self.flash(_('Forbidden'), type="warning")
252            self.redirect(self.url(self.context))
253
[12121]254    def render(self):
255        studentview = StudentBasePDFFormPage(self.context.student,
256            self.request, self.omit_fields)
257        students_utils = getUtility(IStudentsUtils)
258        return students_utils.renderPDF(
259            self, 'clearance_invitation_slip',
260            self.context.student, studentview,
261            omit_fields=self.omit_fields,
262            note=self.note)
263
[13723]264class ExportExaminationScheduleSlip(UtilityView, grok.View):
265    """Deliver a examination schedule slip.
266
[14689]267    This form page is available only in Uniben and AAUE.
[13723]268    """
269    grok.context(ICustomStudent)
270    grok.name('examination_schedule_slip.pdf')
271    grok.require('waeup.viewStudent')
272    prefix = 'form'
273
274    label = u'Examination Schedule Slip'
275
276    omit_fields = (
277        'suspended', 'phone', 'email',
278        'adm_code', 'suspended_comment',
279        'date_of_birth', 'current_level',
280        'current_mode',
281        'entry_session',
282        'flash_notice')
283
284    form_fields = []
285
286    @property
287    def note(self):
288        return """
289<br /><br /><br /><br /><font size='12'>
290Your examination date, time and venue is scheduled as follows:
291<br /><br />
292<strong>%s</strong>
293</font>
294
295""" % self.context.flash_notice
296        return
297
298
299    def update(self):
300        if not self.context.flash_notice \
301            or not 'exam' in self.context.flash_notice.lower():
302            self.flash(_('Forbidden'), type="warning")
303            self.redirect(self.url(self.context))
304
305    def render(self):
306        studentview = StudentBasePDFFormPage(self.context.student,
307            self.request, self.omit_fields)
308        students_utils = getUtility(IStudentsUtils)
309        return students_utils.renderPDF(
310            self, 'examination_schedule_slip',
311            self.context.student, studentview,
312            omit_fields=self.omit_fields,
313            note=self.note)
314
[15371]315class SwitchLibraryAccessView(UtilityView, grok.View):
316    """ Switch the library attribute
317    """
318    grok.context(ICustomStudent)
319    grok.name('switch_library_access')
320    grok.require('waeup.switchLibraryAccess')
321
322    def update(self):
323        if self.context.library:
324            self.context.library = False
325            self.context.writeLogMessage(self, 'library access disabled')
326            self.flash(_('Library access disabled'))
327        else:
328            self.context.library = True
329            self.context.writeLogMessage(self, 'library access enabled')
330            self.flash(_('Library access enabled'))
331        self.redirect(self.url(self.context))
332        return
333
334    def render(self):
335        return
336
[15352]337class ExportJHLIdCard(UtilityView, grok.View):
[15371]338    """Deliver an id card for the John Harris Library.
[15352]339    """
340    grok.context(ICustomStudent)
341    grok.name('jhl_idcard.pdf')
342    grok.require('waeup.viewStudent')
343    prefix = 'form'
344
[15403]345    label = u"John Harris Library Clearance"
[15352]346
347    omit_fields = (
[15371]348        'suspended', 'email', 'phone',
[15352]349        'adm_code', 'suspended_comment',
[15371]350        'date_of_birth',
[15352]351        'current_mode', 'certificate',
352        'entry_session',
353        'flash_notice')
354
355    form_fields = []
356
357    def _sigsInFooter(self):
[15371]358        isStudent = getattr(
359            self.request.principal, 'user_type', None) == 'student'
360        if isStudent:
361            return ''
[15352]362        return (_("Date, Reader's Signature"),
363                _("Date, Circulation Librarian's Signature"),
364                )
365
[15371]366    def update(self):
367        if not self.context.library:
368            self.flash(_('Forbidden!'), type="danger")
369            self.redirect(self.url(self.context))
370        return
371
[15352]372    @property
373    def note(self):
374        return """
375<br /><br /><br /><br /><font size='12'>
376This is to certify that the bearer whose photograph and other details appear
377 overleaf is a registered user of <b>John Harris Library, University of Benin</b>.
378 The card is not transferable. A replacement fee is charged for a loss,
379 mutilation or otherwise. If found, please, return to John Harris Library,
380 University of Benin, Benin City.
381</font>
382
383"""
384        return
385
386    def render(self):
387        studentview = StudentBasePDFFormPage(self.context.student,
388            self.request, self.omit_fields)
389        students_utils = getUtility(IStudentsUtils)
390        return students_utils.renderPDF(
391            self, 'jhl_idcard',
392            self.context.student, studentview,
393            omit_fields=self.omit_fields,
394            sigs_in_footer=self._sigsInFooter(),
395            note=self.note)
396
[14834]397class ExportJUPEBResultSlip(ExportExaminationScheduleSlip):
398    """Deliver a JUPEB result slip.
399
400    This form page is available only in Uniben.
401    """
402
403    grok.name('jupeb_result_slip.pdf')
404    label = u'JUPEB Result Slip'
405
406    @property
407    def note(self):
408        return """
409<br /><br /><br /><br /><font size='12'>
410<strong>%s</strong>
411</font>
412<br /><br /><br /><br />
413<font size='8'>
414Key: A = 5, B = 4, C = 3, D = 2, E = 1, F = 0, X = Absent, Q = Cancelled
415</font>
416
417""" % self.context.flash_notice
418        return
419
420    def update(self):
[14902]421        if not self.context.flash_notice or not self.context.is_jupeb \
[14835]422            or not 'results' in self.context.flash_notice.lower():
[14834]423            self.flash(_('Forbidden'), type="warning")
424            self.redirect(self.url(self.context))
425
[12856]426class CustomStudentPersonalDisplayFormPage(
427    NigeriaStudentPersonalDisplayFormPage):
428    """ Page to display student personal data
429    """
430
431    form_fields = grok.AutoFields(ICustomStudentPersonal)
432    form_fields['perm_address'].custom_widget = BytesDisplayWidget
433    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
434    form_fields[
435        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
436
437class CustomStudentPersonalManageFormPage(
438    NigeriaStudentPersonalManageFormPage):
439    """ Page to manage personal data
440    """
441
442    form_fields = grok.AutoFields(ICustomStudentPersonal)
443    form_fields['personal_updated'].for_display = True
444    form_fields[
445        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
446
[13085]447class CstomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
448    """ Page to edit personal data
449    """
450    form_fields = grok.AutoFields(
451        ICustomStudentPersonalEdit).omit('personal_updated')
452
[9210]453class StudyCourseCOEditFormPage(KofaEditFormPage):
[9281]454    """ Page to edit the student study course data by clearance officers.
[9210]455
456    This form page is available only in Uniben.
457    """
458    grok.context(ICustomStudentStudyCourse)
459    grok.name('edit_level')
460    grok.require('waeup.clearStudent')
461    label = _('Edit current level')
462    pnav = 4
463    form_fields = grok.AutoFields(
464        ICustomStudentStudyCourse).select('current_level')
465
466    def update(self):
467        if not (self.context.is_current and
468            self.context.student.state == REQUESTED):
469            emit_lock_message(self)
470            return
471        super(StudyCourseCOEditFormPage, self).update()
472        return
473
474    @action(_('Save'), style='primary')
475    def save(self, **data):
476        try:
477            msave(self, **data)
478        except ConstraintNotSatisfied:
479            # The selected level might not exist in certificate
480            self.flash(_('Current level not available for certificate.'))
481            return
482        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
[9281]483        return
484
485class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
486    """ Page to edit the student study level data by students.
487
488    """
[9686]489    grok.template('studyleveleditpage')
[9281]490
[9686]491class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
492    """ Page to display student study levels
493    """
494    grok.template('studylevelpage')
495
[13063]496class CustomExportPDFCourseRegistrationSlip(
497    ExportPDFCourseRegistrationSlip):
[9686]498    """Deliver a PDF slip of the context.
499    """
500
[9921]501    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
[15404]502        'level_verdict', 'gpa', 'level', 'transcript_remark')
[9921]503
[12855]504    def update(self):
505        if self.context.student.state != REGISTERED \
506            or self.context.student.current_level != self.context.level:
507            self.flash(_('Forbidden'), type="warning")
508            self.redirect(self.url(self.context))
509
[10441]510    @property
511    def tabletitle(self):
512        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
513        tabletitle = []
514        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
515            target_language=portal_language))
516        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
517            target_language=portal_language))
518        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
519            target_language=portal_language))
520        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
521            target_language=portal_language))
522        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
523            target_language=portal_language))
524        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
525            target_language=portal_language))
526        return tabletitle
527
[9686]528    def render(self):
529        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]530        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
531        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
532        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
533        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
534        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
[9686]535        studentview = StudentBasePDFFormPage(self.context.student,
536            self.request, self.omit_fields)
537        students_utils = getUtility(IStudentsUtils)
[10441]538
539        tabledata = []
540        tableheader = []
541        for i in range(1,7):
542            tabledata.append(sorted(
543                [value for value in self.context.values() if value.semester == i],
544                key=lambda value: str(value.semester) + value.code))
545            tableheader.append([(Code,'code', 2.5),
546                             (Title,'title', 5),
547                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
548                             (Cred, 'credits', 1.5),
549                             ])
[9686]550        return students_utils.renderPDF(
551            self, 'course_registration_slip.pdf',
552            self.context.student, studentview,
[10441]553            tableheader=tableheader,
554            tabledata=tabledata,
[10271]555            omit_fields=self.omit_fields
[9908]556            )
[9848]557
[15401]558class ExportPDFCourseResultSlip(ExportPDFCourseRegistrationSlip):
[9848]559    """Deliver a PDF slip of the context.
560    """
561
562    grok.name('course_result_slip.pdf')
563
[15401]564    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level')
565
[9848]566    @property
[10441]567    def tabletitle(self):
568        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
569        tabletitle = []
570        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
571            target_language=portal_language))
572        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
573            target_language=portal_language))
574        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
575            target_language=portal_language))
576        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
577            target_language=portal_language))
578        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
579            target_language=portal_language))
580        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
581            target_language=portal_language))
582        return tabletitle
583
584    @property
[9848]585    def label(self):
586        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
587        lang = self.request.cookies.get('kofa.language', portal_language)
588        level_title = translate(self.context.level_title, 'waeup.kofa',
589            target_language=lang)
590        return translate(_('Course Result Slip'),
591            'waeup.uniben', target_language=portal_language) \
592            + ' %s' % level_title
593
594    def render(self):
595        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]596        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
597        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
598        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
599        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
600        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
601        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[9848]602        studentview = StudentBasePDFFormPage(self.context.student,
603            self.request, self.omit_fields)
604        students_utils = getUtility(IStudentsUtils)
[10441]605
606        tabledata = []
607        tableheader = []
608        for i in range(1,7):
609            tabledata.append(sorted(
610                [value for value in self.context.values() if value.semester == i],
611                key=lambda value: str(value.semester) + value.code))
612            tableheader.append([(Code,'code', 2.5),
613                             (Title,'title', 5),
614                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
615                             (Cred, 'credits', 1.5),
616                             (Grade, 'grade', 1.5),
617                             ])
[9908]618        return students_utils.renderPDF(
[15401]619            self, 'course_result_slip.pdf',
[9908]620            self.context.student, studentview,
[10441]621            tableheader=tableheader,
622            tabledata=tabledata,
[10271]623            omit_fields=self.omit_fields
[9908]624            )
[9686]625
626class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
627    """ Page to display course tickets
628    """
629    form_fields = grok.AutoFields(ICourseTicket).omit('score')
[11069]630
[13063]631class CustomStudentActivateView(StudentActivateView):
[11069]632    """ Activate student account
633    """
634
635    def update(self):
636        self.context.suspended = False
637        self.context.writeLogMessage(self, 'account activated')
638        history = IObjectHistory(self.context)
639        history.addMessage('Student account activated', user='undisclosed')
640        self.flash(_('Student account has been activated.'))
641        self.redirect(self.url(self.context))
642        return
643
[13063]644class CustomStudentDeactivateView(StudentDeactivateView):
[11069]645    """ Deactivate student account
646    """
647    def update(self):
648        self.context.suspended = True
649        self.context.writeLogMessage(self, 'account deactivated')
650        history = IObjectHistory(self.context)
651        history.addMessage('Student account deactivated', user='undisclosed')
652        self.flash(_('Student account has been deactivated.'))
653        self.redirect(self.url(self.context))
654        return
[12845]655
[13063]656class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
[12845]657    """Deliver a PDF slip of the context.
658    """
659
[15164]660    #def _sigsInFooter(self):
661    #    isStudent = getattr(
662    #        self.request.principal, 'user_type', None) == 'student'
663    #    if not isStudent:
664    #        return (_('D. R. (Exams & Records)'),_('Current Dean of Faculty'),)
665    #    return ()
[12845]666
[14689]667    #def _signatures(self):
668    #    return ([(
669    #        'Current HD<br /> D. R. (Exams & Records)<br /> '
670    #        'For: Registrar')],)
[12845]671
672    def render(self):
673        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
674        Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language)
675        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
676        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
677        Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language)
678        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
679        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
680        studentview = StudentBasePDFFormPage(self.context.student,
681            self.request, self.omit_fields)
682        students_utils = getUtility(IStudentsUtils)
683
684        tableheader = [(Code,'code', 2.5),
685                         (Title,'title', 8.5),
686                         (Term, 'semester', 1.5),
687                         (Cred, 'credits', 1.5),
688                         #(Score, 'score', 1.5),
689                         (Grade, 'grade', 1.5),
690                         ]
691
[15164]692        pdfstream = students_utils.renderPDFTranscript(
[12845]693            self, 'transcript.pdf',
694            self.context.student, studentview,
695            omit_fields=self.omit_fields,
696            tableheader=tableheader,
697            signatures=self._signatures(),
698            sigs_in_footer=self._sigsInFooter(),
[15164]699            digital_sigs=self._digital_sigs(),
700            save_file=self._save_file(),
[13297]701            )
[15164]702        if not pdfstream:
703            self.redirect(self.url(self.context.student))
704            return
705        return pdfstream
[13297]706
707class CustomExportPDFBedTicketSlip(NigeriaExportPDFBedTicketSlip):
708    """Deliver a PDF slip of the context.
709    """
[13317]710    omit_fields = ('password', 'suspended', 'suspended_comment',
[13717]711        'phone', 'adm_code', 'email', 'date_of_birth', 'flash_notice')
[13297]712
[13719]713class CustomPaymentsManageFormPage(PaymentsManageFormPage):
714    """ Page to manage the student payments. This manage form page is for
715    both students and students officers. Uniben does not allow students
716    to remove any payment ticket.
717    """
718    @property
719    def manage_payments_allowed(self):
[13723]720        return checkPermission('waeup.manageStudent', self.context)
[15267]721
[15975]722class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
723    """ Page to view bed tickets.
724    """
725    with_hostel_selection = True
726
[15267]727class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
728    """ Page to manage bed tickets.
729    This manage form page is for both students and students officers.
730    """
[15352]731    with_hostel_selection = True
732
733class CustomStudentBaseEditFormPage(StudentBaseEditFormPage):
734    """ View to edit student base data
735    """
736    form_fields = grok.AutoFields(ICustomStudentBase).select(
737        'email', 'phone')
738    form_fields['email'].field.required = True
Note: See TracBrowser for help on using the repository browser.