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

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

List all charges on pdf payment slip.

  • Property svn:keywords set to Id
File size: 14.3 KB
Line 
1## $Id: browser.py 13405 2015-11-07 07:20:25Z 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 zope.formlib.textwidgets import BytesDisplayWidget
22from waeup.kofa.browser.layout import UtilityView
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from waeup.kofa.interfaces import IKofaUtils
25from waeup.kofa.students.interfaces import IStudentsUtils, IStudent
26from waeup.kofa.students.workflow import PAID, REGISTERED
27from waeup.kofa.students.browser import (
28    StartClearancePage,
29    StudentBasePDFFormPage,
30    CourseTicketAddFormPage,
31    StudyLevelDisplayFormPage,
32    ExportPDFTranscriptSlip,
33    ExportPDFAdmissionSlip,
34    BedTicketAddPage,
35    StudentFilesUploadPage,
36    )
37from kofacustom.nigeria.students.browser import (
38    NigeriaOnlinePaymentDisplayFormPage,
39    NigeriaOnlinePaymentAddFormPage,
40    NigeriaExportPDFPaymentSlip,
41    NigeriaExportPDFCourseRegistrationSlip,
42    NigeriaExportPDFClearanceSlip,
43    NigeriaStudentPersonalDisplayFormPage,
44    NigeriaStudentPersonalEditFormPage,
45    NigeriaStudentPersonalManageFormPage,
46    NigeriaStudentClearanceEditFormPage,
47    )
48from waeup.aaue.students.interfaces import (
49    ICustomStudentOnlinePayment,
50    ICustomStudentStudyLevel,
51    ICustomStudent,
52    ICustomStudentPersonal,
53    ICustomStudentPersonalEdit,
54    ICustomUGStudentClearance)
55from waeup.aaue.interfaces import MessageFactory as _
56
57class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage):
58    """ Page to display student personal data
59    """
60    form_fields = grok.AutoFields(ICustomStudentPersonal)
61    form_fields['perm_address'].custom_widget = BytesDisplayWidget
62    form_fields['father_address'].custom_widget = BytesDisplayWidget
63    form_fields['mother_address'].custom_widget = BytesDisplayWidget
64    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
65    form_fields[
66        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
67
68class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
69    """ Page to edit personal data
70    """
71    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated')
72
73class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage):
74    """ Page to edit personal data
75    """
76    form_fields = grok.AutoFields(ICustomStudentPersonal)
77    form_fields['personal_updated'].for_display = True
78    form_fields[
79        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
80
81class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
82    """ View to edit student clearance data by student
83    """
84
85    @property
86    def form_fields(self):
87        if self.context.is_postgrad:
88            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
89            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
90            'physical_clearance_date')
91        else:
92            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
93            'clearance_locked', 'clr_code', 'officer_comment',
94            'physical_clearance_date')
95        return form_fields
96
97class CustomStartClearancePage(StartClearancePage):
98    with_ac = False
99
100    @property
101    def all_required_fields_filled(self):
102        if not self.context.email:
103            return _("Email address is missing."), 'edit_base'
104        if not self.context.phone:
105            return _("Phone number is missing."), 'edit_base'
106        if not self.context.father_name:
107            return _("Personal data form is not properly filled."), 'edit_personal'
108        return
109
110class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
111    """ Page to view an online payment ticket
112    """
113    grok.context(ICustomStudentOnlinePayment)
114    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
115        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
116    form_fields[
117        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
118    form_fields[
119        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
120
121class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
122    """ Page to add an online payment ticket
123    """
124    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
125        'p_category')
126
127class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
128    """Deliver a PDF slip of the context.
129    """
130    grok.context(ICustomStudentOnlinePayment)
131    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
132        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
133    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
134    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
135
136    @property
137    def note(self):
138        student = self.context.student
139        current_session = student['studycourse'].current_session
140        try:
141            academic_session = grok.getSite()['configuration'][str(current_session)]
142        except KeyError:
143            academic_session = None
144        text =  '\n\n The amounts include: '
145        text += '250.0 Naira Transaction Charge'
146        if self.context.p_category == 'schoolfee_incl' and academic_session:
147            text += (', %s Naira Student Welfare Assurance Fee and %s Naira Students\' Union Dues'
148                     % (academic_session.welfare_fee, academic_session.union_fee))
149        elif self.context.p_category == 'clearance_incl' and academic_session:
150            text += (', %s Naira Matriculation Gown Fee and %s Naira Lapel/File Fee'
151                     % (academic_session.matric_gown_fee, academic_session.lapel_fee))
152        return text + '.'
153
154class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
155    """ Page to display student study levels
156    """
157    grok.context(ICustomStudentStudyLevel)
158    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
159        'total_credits', 'gpa', 'level')
160    form_fields[
161        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
162
163class CustomExportPDFCourseRegistrationSlip(
164    NigeriaExportPDFCourseRegistrationSlip):
165    """Deliver a PDF slip of the context.
166    """
167    grok.context(ICustomStudentStudyLevel)
168    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
169        'level_session', 'level_verdict',
170        'validated_by', 'validation_date', 'gpa', 'level')
171
172    omit_fields = ('password', 'suspended', 'suspended_comment',
173        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
174        'department', 'current_mode', 'current_level')
175
176    def update(self):
177        if self.context.student.state != REGISTERED \
178            and self.context.student.current_level == self.context.level:
179            self.flash(_('Forbidden'), type="warning")
180            self.redirect(self.url(self.context))
181
182    @property
183    def label(self):
184        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
185        lang = self.request.cookies.get('kofa.language', portal_language)
186        level_title = translate(self.context.level_title, 'waeup.kofa',
187            target_language=lang)
188        line0 = ''
189        if self.context.student.current_mode.endswith('_pt'):
190            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
191        line1 = translate(_('Course Registration Slip'),
192            'waeup.kofa', target_language=portal_language) \
193            + ' %s' % level_title
194        line2 = translate(_('Session'),
195            'waeup.kofa', target_language=portal_language) \
196            + ' %s' % self.context.getSessionString
197        return '%s%s\n%s' % (line0, line1, line2)
198
199    @property
200    def title(self):
201        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
202        return translate(_('Units Registered'), 'waeup.kofa',
203            target_language=portal_language)
204
205    def _signatures(self):
206        return (
207            [('I have selected the course on the advise of my Head of '
208             'Department. <br>', _('Student\'s Signature'), '<br>')],
209            [('This student has satisfied the department\'s requirements. '
210             'I recommend to approve the course registration. <br>',
211             _('Head of Department\'s Signature'), '<br>')],
212            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
213            [('', _('Director\'s Signature'))]
214            )
215
216    def render(self):
217        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
218        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
219        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
220        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
221        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
222        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
223        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
224        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
225            target_language=portal_language)
226        studentview = StudentBasePDFFormPage(self.context.student,
227            self.request, self.omit_fields)
228        students_utils = getUtility(IStudentsUtils)
229
230        tabledata = []
231        tableheader = []
232        contenttitle = []
233        for i in range(1,7):
234            tabledata.append(sorted(
235                [value for value in self.context.values() if value.semester == i],
236                key=lambda value: str(value.semester) + value.code))
237            tableheader.append([(Code,'code', 2.0),
238                               (Title,'title', 7),
239                               (Cred, 'credits', 1.5),
240                               (Score, 'score', 1.4),
241                               (Grade, 'grade', 1.4),
242                               (Signature, 'dummy', 3),
243                               ])
244        if len(self.label.split('\n')) == 3:
245            topMargin = 1.9
246        elif len(self.label.split('\n')) == 2:
247            topMargin = 1.7
248        else:
249            topMargin = 1.5
250        return students_utils.renderPDF(
251            self, 'course_registration_slip.pdf',
252            self.context.student, studentview,
253            tableheader=tableheader,
254            tabledata=tabledata,
255            signatures=self._signatures(),
256            topMargin=topMargin,
257            omit_fields=self.omit_fields
258            )
259
260class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
261    """Deliver a PDF slip of the context.
262    """
263
264    def _sigsInFooter(self):
265        return []
266
267    def _signatures(self):
268        return ([(
269            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
270            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
271
272class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
273    """Deliver a PDF Admission slip.
274    """
275
276    @property
277    def label(self):
278        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
279        return translate(_('e-Admission Slip \n'),
280            'waeup.kofa', target_language=portal_language) \
281            + ' %s' % self.context.display_fullname
282
283class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
284    """Deliver a PDF slip of the context.
285    """
286
287    @property
288    def label(self):
289        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
290        return translate(_('Clearance Slip\n'),
291            'waeup.kofa', target_language=portal_language) \
292            + ' %s' % self.context.display_fullname
293
294class StudentGetMatricNumberPage(UtilityView, grok.View):
295    """ Construct and set the matriculation number.
296    """
297    grok.context(IStudent)
298    grok.name('get_matric_number')
299    grok.require('waeup.viewStudent')
300
301    def update(self):
302        students_utils = getUtility(IStudentsUtils)
303        msg, mnumber = students_utils.setMatricNumber(self.context)
304        if msg:
305            self.flash(msg, type="danger")
306        else:
307            self.flash(_('Matriculation number %s assigned.' % mnumber))
308            self.context.writeLogMessage(self, '%s assigned' % mnumber)
309        self.redirect(self.url(self.context))
310        return
311
312    def render(self):
313        return
314
315class ExportPDFMatricNumberSlip(UtilityView, grok.View):
316    """Deliver a PDF notification slip.
317    """
318    grok.context(ICustomStudent)
319    grok.name('matric_number_slip.pdf')
320    grok.require('waeup.viewStudent')
321    prefix = 'form'
322
323    form_fields = grok.AutoFields(ICustomStudent).select(
324        'student_id', 'matric_number')
325    omit_fields = ('date_of_birth', 'current_level')
326
327    @property
328    def label(self):
329        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
330        return translate(_('Matriculation Number Slip\n'),
331            'waeup.kofa', target_language=portal_language) \
332            + ' %s' % self.context.display_fullname
333
334    def render(self):
335        if self.context.state not in (PAID,) or not self.context.is_fresh \
336            or not self.context.matric_number:
337            self.flash('Not allowed.', type="danger")
338            self.redirect(self.url(self.context))
339            return
340        students_utils = getUtility(IStudentsUtils)
341        pre_text = _('Congratulations! Your acceptance fee and school fees ' +
342                     'payments have been received and your matriculation ' +
343                     'number generated with details as follows.')
344        return students_utils.renderPDFAdmissionLetter(self,
345            self.context.student, omit_fields=self.omit_fields,
346            pre_text=pre_text, post_text='')
347
348class CustomBedTicketAddPage(BedTicketAddPage):
349    with_ac = False
350
351class CustomStudentFilesUploadPage(StudentFilesUploadPage):
352    """ View to upload files by student. Inherit from same class in
353    base package, not from kofacustom.nigeria which
354    requires that no application slip exists.
355    """
Note: See TracBrowser for help on using the repository browser.