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

Last change on this file since 15730 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
Line 
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
20from zope.security import checkPermission
21from zope.schema.interfaces import ConstraintNotSatisfied
22from zope.formlib.textwidgets import BytesDisplayWidget
23from zope.component import getUtility
24from hurry.workflow.interfaces import IWorkflowInfo
25from waeup.kofa.interfaces import (
26    REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory)
27from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
28from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView
29from waeup.kofa.students.browser import (
30    StudentBaseEditFormPage,
31    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
32    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
33    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
34    msave, emit_lock_message,
35    StudentActivateView, StudentDeactivateView,
36    ExportPDFTranscriptSlip,
37    PaymentsManageFormPage,
38    StartClearancePage)
39from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
40    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
41    GRADUATED, FORBIDDEN_POSTGRAD_TRANS)
42from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
43from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
44from kofacustom.nigeria.students.browser import (
45    NigeriaOnlinePaymentDisplayFormPage,
46    NigeriaStudentBaseManageFormPage,
47    NigeriaStudentClearanceEditFormPage,
48    NigeriaOnlinePaymentAddFormPage,
49    NigeriaExportPDFPaymentSlip,
50    NigeriaExportPDFClearanceSlip,
51    NigeriaExportPDFBedTicketSlip,
52    NigeriaStudentPersonalDisplayFormPage,
53    NigeriaStudentPersonalManageFormPage,
54    NigeriaStudentPersonalEditFormPage,
55    NigeriaAccommodationManageFormPage,
56    NigeriaStudentBaseDisplayFormPage,
57    )
58
59from waeup.uniben.students.interfaces import (
60    ICustomStudent,
61    ICustomStudentBase,
62    ICustomStudentOnlinePayment,
63    ICustomStudentStudyCourse,
64    ICustomStudentStudyLevel,
65    ICustomUGStudentClearance,
66    ICustomPGStudentClearance,
67    ICustomStudentPersonal,
68    ICustomStudentPersonalEdit)
69from waeup.uniben.interfaces import MessageFactory as _
70
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
87class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
88    """ Page to view an online payment ticket
89    """
90    grok.context(ICustomStudentOnlinePayment)
91    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
92        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
93    form_fields[
94        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
95    form_fields[
96        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
97
98class CustomStartClearancePage(StartClearancePage):
99
100    @property
101    def with_ac(self):
102        if self.context.faccode == 'DCOEM':
103            return False
104        return True
105
106class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
107    """ View to edit student clearance data by student
108    """
109
110    @property
111    def form_fields(self):
112        if self.context.is_postgrad:
113            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
114            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
115            'physical_clearance_date')
116        else:
117            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
118            'clearance_locked', 'clr_code', 'officer_comment',
119            'physical_clearance_date')
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
125    def dataNotComplete(self):
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.')
135        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
136        #    return _('No second sitting result uploaded.')
137        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
138            return _('No affidavit of non-membership of secret cults uploaded.')
139        return False
140
141class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
142    """ Page to add an online payment ticket
143    """
144    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
145        'p_combi')
146
147class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
148    """Deliver a PDF slip of the context.
149    """
150    grok.context(ICustomStudentOnlinePayment)
151    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
152        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
153    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
154    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
155
156
157class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
158    """Deliver a PDF slip of the context.
159    """
160
161    @property
162    def omit_fields(self):
163        omit_fields = ('password', 'suspended', 'suspended_comment',
164                       'phone', 'adm_code', 'email', 'date_of_birth',
165                       'flash_notice')
166        if self.context.is_jupeb:
167            omit_fields += ('faculty', 'department')
168        return omit_fields
169
170    @property
171    def label(self):
172        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
173        line0 = ''
174        if self.context.is_jupeb:
175            line0 = 'Joint Universities Preliminary Examinations Board (JUPEB)\n'
176        line1 = translate(_('Clearance Slip of'),
177            'waeup.kofa', target_language=portal_language) \
178            + ' %s' % self.context.display_fullname
179        return '%s%s' % (line0, line1)
180
181    def _sigsInFooter(self):
182        isStudent = getattr(
183            self.request.principal, 'user_type', None) == 'student'
184        if not isStudent and self.context.state in (CLEARED, RETURNING):
185            return (_('Date, Student Signature'),
186                    _('Date, Clearance Officer Signature'),
187                    )
188        return ()
189
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(),
197            sigs_in_footer=self._sigsInFooter(), show_scans=False,
198            omit_fields=self.omit_fields)
199
200
201class ExportClearanceInvitationSlip(UtilityView, grok.View):
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
211    label = u'Invitation Letter for Physical Clearance'
212
213    omit_fields = (
214        'suspended', 'phone', 'email',
215        'adm_code', 'suspended_comment',
216        'date_of_birth', 'current_level',
217        'department', 'current_mode',
218        'entry_session', 'matric_number', 'sex',
219        'flash_notice')
220
221    form_fields = []
222
223    @property
224    def note(self):
225        if self.context.physical_clearance_date:
226            return """
227<br /><br /><br /><br /><font size='12'>
228Dear %s,
229<br /><br /><br />
230You are invited for your physical clearance on:
231<br /><br />
232<strong>%s</strong>.
233<br /><br />
234Please bring along this letter of invitation to the University Main Auditorium
235<br /><br />
236on your clearance date.
237<br /><br /><br />
238Signed,
239<br /><br />
240The Registrar<br />
241</font>
242
243""" % (self.context.display_fullname, self.context.physical_clearance_date)
244        return
245
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
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
263class ExportExaminationScheduleSlip(UtilityView, grok.View):
264    """Deliver a examination schedule slip.
265
266    This form page is available only in Uniben and AAUE.
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
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
336class ExportJHLIdCard(UtilityView, grok.View):
337    """Deliver an id card for the John Harris Library.
338    """
339    grok.context(ICustomStudent)
340    grok.name('jhl_idcard.pdf')
341    grok.require('waeup.viewStudent')
342    prefix = 'form'
343
344    label = u"John Harris Library Clearance"
345
346    omit_fields = (
347        'suspended', 'email', 'phone',
348        'adm_code', 'suspended_comment',
349        'date_of_birth',
350        'current_mode', 'certificate',
351        'entry_session',
352        'flash_notice')
353
354    form_fields = []
355
356    def _sigsInFooter(self):
357        isStudent = getattr(
358            self.request.principal, 'user_type', None) == 'student'
359        if isStudent:
360            return ''
361        return (_("Date, Reader's Signature"),
362                _("Date, Circulation Librarian's Signature"),
363                )
364
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
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
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):
420        if not self.context.flash_notice or not self.context.is_jupeb \
421            or not 'results' in self.context.flash_notice.lower():
422            self.flash(_('Forbidden'), type="warning")
423            self.redirect(self.url(self.context))
424
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
446class CstomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
447    """ Page to edit personal data
448    """
449    form_fields = grok.AutoFields(
450        ICustomStudentPersonalEdit).omit('personal_updated')
451
452class StudyCourseCOEditFormPage(KofaEditFormPage):
453    """ Page to edit the student study course data by clearance officers.
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__))
482        return
483
484class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
485    """ Page to edit the student study level data by students.
486
487    """
488    grok.template('studyleveleditpage')
489
490class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
491    """ Page to display student study levels
492    """
493    grok.template('studylevelpage')
494
495class CustomExportPDFCourseRegistrationSlip(
496    ExportPDFCourseRegistrationSlip):
497    """Deliver a PDF slip of the context.
498    """
499
500    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
501        'level_verdict', 'gpa', 'level', 'transcript_remark')
502
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
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
527    def render(self):
528        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
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)
534        studentview = StudentBasePDFFormPage(self.context.student,
535            self.request, self.omit_fields)
536        students_utils = getUtility(IStudentsUtils)
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                             ])
549        return students_utils.renderPDF(
550            self, 'course_registration_slip.pdf',
551            self.context.student, studentview,
552            tableheader=tableheader,
553            tabledata=tabledata,
554            omit_fields=self.omit_fields
555            )
556
557class ExportPDFCourseResultSlip(ExportPDFCourseRegistrationSlip):
558    """Deliver a PDF slip of the context.
559    """
560
561    grok.name('course_result_slip.pdf')
562
563    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level')
564
565    @property
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
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
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)
601        studentview = StudentBasePDFFormPage(self.context.student,
602            self.request, self.omit_fields)
603        students_utils = getUtility(IStudentsUtils)
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                             ])
617        return students_utils.renderPDF(
618            self, 'course_result_slip.pdf',
619            self.context.student, studentview,
620            tableheader=tableheader,
621            tabledata=tabledata,
622            omit_fields=self.omit_fields
623            )
624
625class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
626    """ Page to display course tickets
627    """
628    form_fields = grok.AutoFields(ICourseTicket).omit('score')
629
630class CustomStudentActivateView(StudentActivateView):
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
643class CustomStudentDeactivateView(StudentDeactivateView):
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
654
655class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
656    """Deliver a PDF slip of the context.
657    """
658
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 ()
665
666    #def _signatures(self):
667    #    return ([(
668    #        'Current HD<br /> D. R. (Exams & Records)<br /> '
669    #        'For: Registrar')],)
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
691        pdfstream = students_utils.renderPDFTranscript(
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(),
698            digital_sigs=self._digital_sigs(),
699            save_file=self._save_file(),
700            )
701        if not pdfstream:
702            self.redirect(self.url(self.context.student))
703            return
704        return pdfstream
705
706class CustomExportPDFBedTicketSlip(NigeriaExportPDFBedTicketSlip):
707    """Deliver a PDF slip of the context.
708    """
709    omit_fields = ('password', 'suspended', 'suspended_comment',
710        'phone', 'adm_code', 'email', 'date_of_birth', 'flash_notice')
711
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):
719        return checkPermission('waeup.manageStudent', self.context)
720
721class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
722    """ Page to manage bed tickets.
723    This manage form page is for both students and students officers.
724    """
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.