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

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

Render note on payment slips which indicates charges included.

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