source: main/waeup.aaue/trunk/src/waeup/aaue/students/browser.py @ 10664

Last change on this file since 10664 was 10566, checked in by Henrik Bettermann, 11 years ago

Set logo and watermark on landscape pdf slips.

  • Property svn:keywords set to Id
File size: 7.3 KB
RevLine 
[8911]1## $Id: browser.py 10566 2013-08-30 05:24: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
[9914]20from zope.component import getUtility
[8911]21from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[9914]22from waeup.kofa.interfaces import IKofaUtils
23from waeup.kofa.students.interfaces import IStudentsUtils
24from waeup.kofa.students.browser import (
25    StudentBasePDFFormPage,
26    CourseTicketAddFormPage,
27    StudyLevelDisplayFormPage,
[10566]28    ExportPDFTranscriptPage,
[10269]29    )
[8911]30from kofacustom.nigeria.students.browser import (
31    NigeriaOnlinePaymentDisplayFormPage,
32    NigeriaOnlinePaymentAddFormPage,
[10269]33    NigeriaExportPDFPaymentSlipPage,
34    NigeriaExportPDFCourseRegistrationSlipPage
35    )
[9496]36from waeup.aaue.students.interfaces import (
[9914]37    ICustomStudentOnlinePayment,
38    ICustomStudentStudyLevel)
39from waeup.aaue.interfaces import MessageFactory as _
[8911]40
41class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
42    """ Page to view an online payment ticket
43    """
44    grok.context(ICustomStudentOnlinePayment)
[9853]45    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9990]46        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]47    form_fields[
48        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
49    form_fields[
50        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
51
52class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
53    """ Page to add an online payment ticket
54    """
55    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
56        'p_category')
57
58class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
59    """Deliver a PDF slip of the context.
60    """
61    grok.context(ICustomStudentOnlinePayment)
[9853]62    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9990]63        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]64    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9496]65    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9914]66
67class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
68    """ Page to display student study levels
69    """
70    grok.context(ICustomStudentStudyLevel)
[10480]71    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
72        'total_credits', 'gpa')
[9914]73    form_fields[
74        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
75
76class CustomExportPDFCourseRegistrationSlipPage(
[10269]77    NigeriaExportPDFCourseRegistrationSlipPage):
[9914]78    """Deliver a PDF slip of the context.
79    """
80    grok.context(ICustomStudentStudyLevel)
81    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
[10102]82        'level_session', 'level_verdict',
[10480]83        'validated_by', 'validation_date', 'gpa')
[9914]84
[10269]85    omit_fields = ('password', 'suspended', 'suspended_comment',
86        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'department')
87
[9914]88    @property
89    def label(self):
90        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
91        lang = self.request.cookies.get('kofa.language', portal_language)
92        level_title = translate(self.context.level_title, 'waeup.kofa',
93            target_language=lang)
94        line0 = ''
95        if self.context.student.current_mode.endswith('_pt'):
96            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
97        line1 = translate(_('Course Registration Slip'),
98            'waeup.kofa', target_language=portal_language) \
99            + ' %s' % level_title
100        line2 = translate(_('Session'),
101            'waeup.kofa', target_language=portal_language) \
102            + ' %s' % self.context.getSessionString
103        return '%s%s\n%s' % (line0, line1, line2)
104
105    @property
106    def title(self):
107        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
108        return translate(_('Units Registered'), 'waeup.kofa',
109            target_language=portal_language)
110
111    def _signatures(self):
[9968]112        return (
113            [('I have selected the course on the advise of my Head of '
114             'Department. <br>', _('Student\'s Signature'), '<br>')],
115            [('This student has satisfied the department\'s requirements. '
116             'I recommend to approve the course registration. <br>',
117             _('Head of Department\'s Signature'), '<br>')],
118            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
119            [('', _('Director\'s Signature'))]
120            )
[9914]121
122    def render(self):
123        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
124        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
125        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
126        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
127        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
128        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
129        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[10269]130        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
[9914]131            target_language=portal_language)
132        studentview = StudentBasePDFFormPage(self.context.student,
133            self.request, self.omit_fields)
134        students_utils = getUtility(IStudentsUtils)
[10442]135
136        tabledata = []
137        tableheader = []
138        contenttitle = []
139        for i in range(1,7):
140            tabledata.append(sorted(
141                [value for value in self.context.values() if value.semester == i],
142                key=lambda value: str(value.semester) + value.code))
143            tableheader.append([(Code,'code', 2.0),
144                               (Title,'title', 7),
145                               (Cred, 'credits', 1.5),
146                               (Score, 'score', 1.4),
147                               (Grade, 'grade', 1.4),
148                               (Signature, 'dummy', 3),
149                               ])
[9914]150        if len(self.label.split('\n')) == 3:
151            topMargin = 1.9
152        elif len(self.label.split('\n')) == 2:
153            topMargin = 1.7
154        else:
155            topMargin = 1.5
156        return students_utils.renderPDF(
157            self, 'course_registration_slip.pdf',
158            self.context.student, studentview,
[10442]159            tableheader=tableheader,
160            tabledata=tabledata,
[9914]161            signatures=self._signatures(),
[10269]162            topMargin=topMargin,
163            omit_fields=self.omit_fields
[9914]164            )
[10566]165
166class CustomExportPDFTranscriptPage(ExportPDFTranscriptPage):
167    """Deliver a PDF slip of the context.
168    """
169
170    def _sigsInFooter(self):
171        return []
172
173    def _signatures(self):
174        return ([(
175            'A.O Esekigbe <br /> Deputy Registrar  <br /> '
176            'Exams, Records And Data <br /> For: Registrar')],)
Note: See TracBrowser for help on using the repository browser.