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

Last change on this file since 13489 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
Line 
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
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    NigeriaAccommodationManageFormPage,
48    )
49from waeup.aaue.students.interfaces import (
50    ICustomStudentOnlinePayment,
51    ICustomStudentStudyLevel,
52    ICustomStudent,
53    ICustomStudentPersonal,
54    ICustomStudentPersonalEdit,
55    ICustomUGStudentClearance)
56from waeup.aaue.interswitch.browser import gateway_net_amt
57from waeup.aaue.interfaces import MessageFactory as _
58
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
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
99class CustomStartClearancePage(StartClearancePage):
100    with_ac = False
101
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
112class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
113    """ Page to view an online payment ticket
114    """
115    grok.context(ICustomStudentOnlinePayment)
116    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
117        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
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
129class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
130    """Deliver a PDF slip of the context.
131    """
132    grok.context(ICustomStudentOnlinePayment)
133    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
134        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
135    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
136    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
137
138    @property
139    def note(self):
140        p_session = self.context.p_session
141        try:
142            academic_session = grok.getSite()['configuration'][str(p_session)]
143        except KeyError:
144            academic_session = None
145        text =  '\n\n The Amount Authorized is inclusive of: '
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 += ('School Fee, '
150                     '%s Naira Student Union Dues, '
151                     '%s Naira Student Welfare Assurance Fee and '
152                     % (union_fee, welfare_fee))
153        elif self.context.p_category in (
154            'clearance_incl', 'clearance_medical_incl') and academic_session:
155            matric_gown_fee = gateway_net_amt(academic_session.matric_gown_fee)
156            lapel_fee = gateway_net_amt(academic_session.lapel_fee)
157            text += ('Acceptance Fee, '
158                     '%s Naira Matriculation Gown Fee, '
159                     '%s Naira Lapel/File Fee and '
160                     % (matric_gown_fee, lapel_fee))
161        return text + '250.0 Naira Transaction Charge.'
162
163class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
164    """ Page to display student study levels
165    """
166    grok.context(ICustomStudentStudyLevel)
167    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
168        'total_credits', 'gpa', 'level')
169    form_fields[
170        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
171
172class CustomExportPDFCourseRegistrationSlip(
173    NigeriaExportPDFCourseRegistrationSlip):
174    """Deliver a PDF slip of the context.
175    """
176    grok.context(ICustomStudentStudyLevel)
177    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
178        'level_session', 'level_verdict',
179        'validated_by', 'validation_date', 'gpa', 'level')
180
181    omit_fields = ('password', 'suspended', 'suspended_comment',
182        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
183        'department', 'current_mode', 'current_level')
184
185    def update(self):
186        if self.context.student.state != REGISTERED \
187            and self.context.student.current_level == self.context.level:
188            self.flash(_('Forbidden'), type="warning")
189            self.redirect(self.url(self.context))
190
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):
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            )
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)
233        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
234            target_language=portal_language)
235        studentview = StudentBasePDFFormPage(self.context.student,
236            self.request, self.omit_fields)
237        students_utils = getUtility(IStudentsUtils)
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                               ])
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,
262            tableheader=tableheader,
263            tabledata=tabledata,
264            signatures=self._signatures(),
265            topMargin=topMargin,
266            omit_fields=self.omit_fields
267            )
268
269class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
270    """Deliver a PDF slip of the context.
271    """
272
273    def _sigsInFooter(self):
274        return []
275
276    def _signatures(self):
277        return ([(
278            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
279            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
280
281class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
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
291
292class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
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
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))
317            self.context.writeLogMessage(self, '%s assigned' % mnumber)
318        self.redirect(self.url(self.context))
319        return
320
321    def render(self):
322        return
323
324class ExportPDFMatricNumberSlip(UtilityView, grok.View):
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
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
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)
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.')
359        return students_utils.renderPDFAdmissionLetter(self,
360            self.context.student, omit_fields=self.omit_fields,
361            pre_text=pre_text, post_text='')
362
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
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
402class CustomBedTicketAddPage(BedTicketAddPage):
403    with_ac = False
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.