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

Last change on this file since 13071 was 13059, checked in by Henrik Bettermann, 9 years ago

Rename views according to changes in base package.

Add test_manage_payments_bypass_ac_creation.

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