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

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

Add personal data slip.

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