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

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

Change notre on payment slip.

  • Property svn:keywords set to Id
File size: 14.7 KB
Line 
1## $Id: browser.py 13425 2015-11-10 05:06:58Z 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 Amount Authorized is inclusive of: '
145        if self.context.p_category == 'schoolfee_incl' and academic_session:
146            welfare_fee = gateway_net_amt(academic_session.welfare_fee)
147            union_fee = gateway_net_amt(academic_session.union_fee)
148            text += ('School Fee'
149                     ', %s Naira Students\' Union Dues'
150                     ', %s Naira Student Welfare Assurance Fee'
151                     % (union_fee, welfare_fee))
152        elif self.context.p_category in (
153            'clearance_incl', 'clearance_medical_incl') and academic_session:
154            matric_gown_fee = gateway_net_amt(academic_session.matric_gown_fee)
155            lapel_fee = gateway_net_amt(academic_session.lapel_fee)
156            text += ('Acceptance Fee'
157                     ', %s Naira Matriculation Gown Fee'
158                     ', %s Naira Lapel/File Fee'
159                     % (matric_gown_fee, lapel_fee))
160        return text + ' and 250.0 Naira Transaction Charge.'
161
162class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
163    """ Page to display student study levels
164    """
165    grok.context(ICustomStudentStudyLevel)
166    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
167        'total_credits', 'gpa', 'level')
168    form_fields[
169        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
170
171class CustomExportPDFCourseRegistrationSlip(
172    NigeriaExportPDFCourseRegistrationSlip):
173    """Deliver a PDF slip of the context.
174    """
175    grok.context(ICustomStudentStudyLevel)
176    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
177        'level_session', 'level_verdict',
178        'validated_by', 'validation_date', 'gpa', 'level')
179
180    omit_fields = ('password', 'suspended', 'suspended_comment',
181        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
182        'department', 'current_mode', 'current_level')
183
184    def update(self):
185        if self.context.student.state != REGISTERED \
186            and self.context.student.current_level == self.context.level:
187            self.flash(_('Forbidden'), type="warning")
188            self.redirect(self.url(self.context))
189
190    @property
191    def label(self):
192        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
193        lang = self.request.cookies.get('kofa.language', portal_language)
194        level_title = translate(self.context.level_title, 'waeup.kofa',
195            target_language=lang)
196        line0 = ''
197        if self.context.student.current_mode.endswith('_pt'):
198            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
199        line1 = translate(_('Course Registration Slip'),
200            'waeup.kofa', target_language=portal_language) \
201            + ' %s' % level_title
202        line2 = translate(_('Session'),
203            'waeup.kofa', target_language=portal_language) \
204            + ' %s' % self.context.getSessionString
205        return '%s%s\n%s' % (line0, line1, line2)
206
207    @property
208    def title(self):
209        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
210        return translate(_('Units Registered'), 'waeup.kofa',
211            target_language=portal_language)
212
213    def _signatures(self):
214        return (
215            [('I have selected the course on the advise of my Head of '
216             'Department. <br>', _('Student\'s Signature'), '<br>')],
217            [('This student has satisfied the department\'s requirements. '
218             'I recommend to approve the course registration. <br>',
219             _('Head of Department\'s Signature'), '<br>')],
220            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
221            [('', _('Director\'s Signature'))]
222            )
223
224    def render(self):
225        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
226        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
227        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
228        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
229        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
230        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
231        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
232        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
233            target_language=portal_language)
234        studentview = StudentBasePDFFormPage(self.context.student,
235            self.request, self.omit_fields)
236        students_utils = getUtility(IStudentsUtils)
237
238        tabledata = []
239        tableheader = []
240        contenttitle = []
241        for i in range(1,7):
242            tabledata.append(sorted(
243                [value for value in self.context.values() if value.semester == i],
244                key=lambda value: str(value.semester) + value.code))
245            tableheader.append([(Code,'code', 2.0),
246                               (Title,'title', 7),
247                               (Cred, 'credits', 1.5),
248                               (Score, 'score', 1.4),
249                               (Grade, 'grade', 1.4),
250                               (Signature, 'dummy', 3),
251                               ])
252        if len(self.label.split('\n')) == 3:
253            topMargin = 1.9
254        elif len(self.label.split('\n')) == 2:
255            topMargin = 1.7
256        else:
257            topMargin = 1.5
258        return students_utils.renderPDF(
259            self, 'course_registration_slip.pdf',
260            self.context.student, studentview,
261            tableheader=tableheader,
262            tabledata=tabledata,
263            signatures=self._signatures(),
264            topMargin=topMargin,
265            omit_fields=self.omit_fields
266            )
267
268class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
269    """Deliver a PDF slip of the context.
270    """
271
272    def _sigsInFooter(self):
273        return []
274
275    def _signatures(self):
276        return ([(
277            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
278            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
279
280class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
281    """Deliver a PDF Admission slip.
282    """
283
284    @property
285    def label(self):
286        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
287        return translate(_('e-Admission Slip \n'),
288            'waeup.kofa', target_language=portal_language) \
289            + ' %s' % self.context.display_fullname
290
291class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
292    """Deliver a PDF slip of the context.
293    """
294
295    @property
296    def label(self):
297        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
298        return translate(_('Clearance Slip\n'),
299            'waeup.kofa', target_language=portal_language) \
300            + ' %s' % self.context.display_fullname
301
302class StudentGetMatricNumberPage(UtilityView, grok.View):
303    """ Construct and set the matriculation number.
304    """
305    grok.context(IStudent)
306    grok.name('get_matric_number')
307    grok.require('waeup.viewStudent')
308
309    def update(self):
310        students_utils = getUtility(IStudentsUtils)
311        msg, mnumber = students_utils.setMatricNumber(self.context)
312        if msg:
313            self.flash(msg, type="danger")
314        else:
315            self.flash(_('Matriculation number %s assigned.' % mnumber))
316            self.context.writeLogMessage(self, '%s assigned' % mnumber)
317        self.redirect(self.url(self.context))
318        return
319
320    def render(self):
321        return
322
323class ExportPDFMatricNumberSlip(UtilityView, grok.View):
324    """Deliver a PDF notification slip.
325    """
326    grok.context(ICustomStudent)
327    grok.name('matric_number_slip.pdf')
328    grok.require('waeup.viewStudent')
329    prefix = 'form'
330
331    form_fields = grok.AutoFields(ICustomStudent).select(
332        'student_id', 'matric_number')
333    omit_fields = ('date_of_birth', 'current_level')
334
335    @property
336    def label(self):
337        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
338        return translate(_('Matriculation Number Slip\n'),
339            'waeup.kofa', target_language=portal_language) \
340            + ' %s' % self.context.display_fullname
341
342    def render(self):
343        if self.context.state not in (PAID,) or not self.context.is_fresh \
344            or not self.context.matric_number:
345            self.flash('Not allowed.', type="danger")
346            self.redirect(self.url(self.context))
347            return
348        students_utils = getUtility(IStudentsUtils)
349        pre_text = _('Congratulations! Your acceptance fee and school fees ' +
350                     'payments have been received and your matriculation ' +
351                     'number generated with details as follows.')
352        return students_utils.renderPDFAdmissionLetter(self,
353            self.context.student, omit_fields=self.omit_fields,
354            pre_text=pre_text, post_text='')
355
356class CustomBedTicketAddPage(BedTicketAddPage):
357    with_ac = False
358
359class CustomStudentFilesUploadPage(StudentFilesUploadPage):
360    """ View to upload files by student. Inherit from same class in
361    base package, not from kofacustom.nigeria which
362    requires that no application slip exists.
363    """
Note: See TracBrowser for help on using the repository browser.