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

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

Do not display p_combi.

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