source: main/waeup.aaue/branches/0.1/src/waeup/aaue/students/browser.py @ 15185

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

Customize admission letter (admission slip).

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