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

Last change on this file since 11831 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
RevLine 
[8911]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
[9914]20from zope.component import getUtility
[11597]21from waeup.kofa.browser.layout import UtilityView
[8911]22from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[9914]23from waeup.kofa.interfaces import IKofaUtils
[11597]24from waeup.kofa.students.interfaces import IStudentsUtils, IStudent
[11607]25from waeup.kofa.students.workflow import PAID
[9914]26from waeup.kofa.students.browser import (
27    StudentBasePDFFormPage,
28    CourseTicketAddFormPage,
29    StudyLevelDisplayFormPage,
[10566]30    ExportPDFTranscriptPage,
[10922]31    ExportPDFAdmissionSlipPage,
[10269]32    )
[8911]33from kofacustom.nigeria.students.browser import (
34    NigeriaOnlinePaymentDisplayFormPage,
35    NigeriaOnlinePaymentAddFormPage,
[10269]36    NigeriaExportPDFPaymentSlipPage,
[11606]37    NigeriaExportPDFCourseRegistrationSlipPage,
38    NigeriaExportPDFClearanceSlipPage,
[10269]39    )
[9496]40from waeup.aaue.students.interfaces import (
[9914]41    ICustomStudentOnlinePayment,
[11607]42    ICustomStudentStudyLevel,
43    ICustomStudent)
[9914]44from waeup.aaue.interfaces import MessageFactory as _
[8911]45
46class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
47    """ Page to view an online payment ticket
48    """
49    grok.context(ICustomStudentOnlinePayment)
[9853]50    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9990]51        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]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)
[9853]67    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9990]68        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]69    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9496]70    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9914]71
[11625]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
[9914]82class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
83    """ Page to display student study levels
84    """
85    grok.context(ICustomStudentStudyLevel)
[10480]86    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
87        'total_credits', 'gpa')
[9914]88    form_fields[
89        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
90
91class CustomExportPDFCourseRegistrationSlipPage(
[10269]92    NigeriaExportPDFCourseRegistrationSlipPage):
[9914]93    """Deliver a PDF slip of the context.
94    """
95    grok.context(ICustomStudentStudyLevel)
96    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
[10102]97        'level_session', 'level_verdict',
[10480]98        'validated_by', 'validation_date', 'gpa')
[9914]99
[10269]100    omit_fields = ('password', 'suspended', 'suspended_comment',
[10689]101        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
[11538]102        'department', 'current_mode', 'current_level')
[10269]103
[9914]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):
[9968]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            )
[9914]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)
[10269]146        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
[9914]147            target_language=portal_language)
148        studentview = StudentBasePDFFormPage(self.context.student,
149            self.request, self.omit_fields)
150        students_utils = getUtility(IStudentsUtils)
[10442]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                               ])
[9914]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,
[10442]175            tableheader=tableheader,
176            tabledata=tabledata,
[9914]177            signatures=self._signatures(),
[10269]178            topMargin=topMargin,
179            omit_fields=self.omit_fields
[9914]180            )
[10566]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 ([(
[11555]191            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
192            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
[10922]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
[11597]204
[11606]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
[11597]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))
[11602]230            self.context.writeLogMessage(self, '%s assigned' % mnumber)
[11597]231        self.redirect(self.url(self.context))
232        return
233
234    def render(self):
[11607]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)
[11609]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.')
[11607]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.