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

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

Determine net amount instead of gateway reduction. This is much easier to handle.

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