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

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

ExportPDFMatricNumberSlipPage and MatricNumberSlipActionButton? added.

  • Property svn:keywords set to Id
File size: 10.4 KB
RevLine 
[8911]1## $Id: browser.py 11607 2014-04-30 05:30:32Z 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
72class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
73    """ Page to display student study levels
74    """
75    grok.context(ICustomStudentStudyLevel)
[10480]76    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
77        'total_credits', 'gpa')
[9914]78    form_fields[
79        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
80
81class CustomExportPDFCourseRegistrationSlipPage(
[10269]82    NigeriaExportPDFCourseRegistrationSlipPage):
[9914]83    """Deliver a PDF slip of the context.
84    """
85    grok.context(ICustomStudentStudyLevel)
86    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
[10102]87        'level_session', 'level_verdict',
[10480]88        'validated_by', 'validation_date', 'gpa')
[9914]89
[10269]90    omit_fields = ('password', 'suspended', 'suspended_comment',
[10689]91        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
[11538]92        'department', 'current_mode', 'current_level')
[10269]93
[9914]94    @property
95    def label(self):
96        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
97        lang = self.request.cookies.get('kofa.language', portal_language)
98        level_title = translate(self.context.level_title, 'waeup.kofa',
99            target_language=lang)
100        line0 = ''
101        if self.context.student.current_mode.endswith('_pt'):
102            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
103        line1 = translate(_('Course Registration Slip'),
104            'waeup.kofa', target_language=portal_language) \
105            + ' %s' % level_title
106        line2 = translate(_('Session'),
107            'waeup.kofa', target_language=portal_language) \
108            + ' %s' % self.context.getSessionString
109        return '%s%s\n%s' % (line0, line1, line2)
110
111    @property
112    def title(self):
113        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
114        return translate(_('Units Registered'), 'waeup.kofa',
115            target_language=portal_language)
116
117    def _signatures(self):
[9968]118        return (
119            [('I have selected the course on the advise of my Head of '
120             'Department. <br>', _('Student\'s Signature'), '<br>')],
121            [('This student has satisfied the department\'s requirements. '
122             'I recommend to approve the course registration. <br>',
123             _('Head of Department\'s Signature'), '<br>')],
124            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
125            [('', _('Director\'s Signature'))]
126            )
[9914]127
128    def render(self):
129        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
130        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
131        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
132        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
133        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
134        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
135        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[10269]136        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
[9914]137            target_language=portal_language)
138        studentview = StudentBasePDFFormPage(self.context.student,
139            self.request, self.omit_fields)
140        students_utils = getUtility(IStudentsUtils)
[10442]141
142        tabledata = []
143        tableheader = []
144        contenttitle = []
145        for i in range(1,7):
146            tabledata.append(sorted(
147                [value for value in self.context.values() if value.semester == i],
148                key=lambda value: str(value.semester) + value.code))
149            tableheader.append([(Code,'code', 2.0),
150                               (Title,'title', 7),
151                               (Cred, 'credits', 1.5),
152                               (Score, 'score', 1.4),
153                               (Grade, 'grade', 1.4),
154                               (Signature, 'dummy', 3),
155                               ])
[9914]156        if len(self.label.split('\n')) == 3:
157            topMargin = 1.9
158        elif len(self.label.split('\n')) == 2:
159            topMargin = 1.7
160        else:
161            topMargin = 1.5
162        return students_utils.renderPDF(
163            self, 'course_registration_slip.pdf',
164            self.context.student, studentview,
[10442]165            tableheader=tableheader,
166            tabledata=tabledata,
[9914]167            signatures=self._signatures(),
[10269]168            topMargin=topMargin,
169            omit_fields=self.omit_fields
[9914]170            )
[10566]171
172class CustomExportPDFTranscriptPage(ExportPDFTranscriptPage):
173    """Deliver a PDF slip of the context.
174    """
175
176    def _sigsInFooter(self):
177        return []
178
179    def _signatures(self):
180        return ([(
[11555]181            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
182            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
[10922]183
184class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
185    """Deliver a PDF Admission slip.
186    """
187
188    @property
189    def label(self):
190        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
191        return translate(_('e-Admission Slip \n'),
192            'waeup.kofa', target_language=portal_language) \
193            + ' %s' % self.context.display_fullname
[11597]194
[11606]195class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
196    """Deliver a PDF slip of the context.
197    """
198
199    @property
200    def label(self):
201        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
202        return translate(_('Clearance Slip\n'),
203            'waeup.kofa', target_language=portal_language) \
204            + ' %s' % self.context.display_fullname
205
[11597]206class StudentGetMatricNumberPage(UtilityView, grok.View):
207    """ Construct and set the matriculation number.
208    """
209    grok.context(IStudent)
210    grok.name('get_matric_number')
211    grok.require('waeup.viewStudent')
212
213    def update(self):
214        students_utils = getUtility(IStudentsUtils)
215        msg, mnumber = students_utils.setMatricNumber(self.context)
216        if msg:
217            self.flash(msg, type="danger")
218        else:
219            self.flash(_('Matriculation number %s assigned.' % mnumber))
[11602]220            self.context.writeLogMessage(self, '%s assigned' % mnumber)
[11597]221        self.redirect(self.url(self.context))
222        return
223
224    def render(self):
[11607]225        return
226
227class ExportPDFMatricNumberSlipPage(UtilityView, grok.View):
228    """Deliver a PDF notification slip.
229    """
230    grok.context(ICustomStudent)
231    grok.name('matric_number_slip.pdf')
232    grok.require('waeup.viewStudent')
233    prefix = 'form'
234
235    form_fields = grok.AutoFields(ICustomStudent).select(
236        'student_id', 'matric_number')
237    omit_fields = ('date_of_birth', 'current_level')
238
239    @property
240    def label(self):
241        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
242        return translate(_('Matriculation Number Slip\n'),
243            'waeup.kofa', target_language=portal_language) \
244            + ' %s' % self.context.display_fullname
245
246    def render(self):
247        if self.context.state not in (PAID,) or not self.context.is_fresh \
248            or not self.context.matric_number:
249            self.flash('Not allowed.', type="danger")
250            self.redirect(self.url(self.context))
251            return
252        students_utils = getUtility(IStudentsUtils)
253        pre_text = _('Congratulations! Your acceptance and school fee payments ' +
254                     'have been received and your matriculation number ' +
255                     'generated with details as follows:')
256        return students_utils.renderPDFAdmissionLetter(self,
257            self.context.student, omit_fields=self.omit_fields,
258            pre_text=pre_text, post_text='')
Note: See TracBrowser for help on using the repository browser.