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

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

Label of NigeriaExportPDFClearanceSlipPage customized.

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