source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/browser.py @ 13307

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

Change slips according to #128.

  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1## $Id: browser.py 13307 2015-10-12 07:02:23Z 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.formlib.textwidgets import BytesDisplayWidget
21from zope.component import getUtility
22from waeup.kofa.interfaces import IKofaUtils
23from waeup.kofa.browser.layout import UtilityView
24from waeup.kofa.students.interfaces import IStudentsUtils
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
26from waeup.kofa.students.browser import (
27    StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlip,
28    StudentBasePDFFormPage)
29from waeup.kwarapoly.students.interfaces import (
30    ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel,
31    ICustomUGStudentClearance, ICustomPGStudentClearance)
32from waeup.kwarapoly.interfaces import MessageFactory as _
33from waeup.kofa.students.workflow import (
34    ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED,
35    VALIDATED, GRADUATED, TRANSCRIPT, CREATED, CLEARANCE)
36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
38    NigeriaOnlinePaymentAddFormPage,
39    NigeriaExportPDFPaymentSlip,
40    NigeriaStudentClearanceDisplayFormPage,
41    NigeriaExportPDFClearanceSlip,
42    NigeriaStudentClearanceEditFormPage,
43    NigeriaExportPDFCourseRegistrationSlip,
44    NigeriaStudentPersonalDisplayFormPage,
45    NigeriaStudentClearanceManageFormPage,
46    NigeriaStudentPersonalEditFormPage,
47    NigeriaStudentPersonalManageFormPage,
48    NigeriaStudentBaseEditFormPage
49    )
50
51from waeup.kwarapoly.students.interfaces import (
52    ICustomStudent,
53    ICustomStudentOnlinePayment,
54    ICustomStudentPersonal,
55    ICustomStudentPersonalEdit
56    )
57
58
59class CustomStudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
60    """ View to edit student base data
61    """
62    form_fields = grok.AutoFields(ICustomStudentBase).select(
63        'email', 'phone', 'sex')
64
65
66class CustomStudentPersonalDisplayFormPage(
67    NigeriaStudentPersonalDisplayFormPage):
68    """ Page to display student personal data
69    """
70    form_fields = grok.AutoFields(ICustomStudentPersonal)
71    form_fields['perm_address'].custom_widget = BytesDisplayWidget
72    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
73    form_fields['corr_address'].custom_widget = BytesDisplayWidget
74    form_fields['sponsor_address'].custom_widget = BytesDisplayWidget
75    form_fields[
76        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77
78
79class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
80    """ Page to edit personal data
81    """
82    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit(
83        'personal_updated')
84
85
86class CustomStudentPersonalManageFormPage(
87    NigeriaStudentPersonalManageFormPage):
88    """ Page to edit personal data
89    """
90    form_fields = grok.AutoFields(ICustomStudentPersonal)
91    form_fields['personal_updated'].for_display = True
92    form_fields[
93        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
94
95
96class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
97    """ Page to view an online payment ticket
98    """
99    grok.context(ICustomStudentOnlinePayment)
100    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
101        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
102    form_fields[
103        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
104    form_fields[
105        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
106
107
108class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
109    """ Page to add an online payment ticket
110    """
111    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
112        'p_category')
113
114
115class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
116    """Deliver a PDF slip of the context.
117    """
118    grok.context(ICustomStudentOnlinePayment)
119    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
120        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
121    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget(
122        'le')
123    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget(
124        'le')
125
126
127class CustomStartClearancePage(StartClearancePage):
128
129    with_ac = False
130
131
132class CustomStudentClearanceDisplayFormPage(
133    NigeriaStudentClearanceDisplayFormPage):
134    """ Page to display student clearance data
135    """
136
137    @property
138    def form_fields(self):
139        if self.context.is_postgrad:
140            form_fields = grok.AutoFields(
141                ICustomPGStudentClearance).omit('clearance_locked')
142        else:
143            form_fields = grok.AutoFields(
144                ICustomUGStudentClearance).omit('clearance_locked')
145        if not getattr(self.context, 'officer_comment'):
146            form_fields = form_fields.omit('officer_comment')
147        else:
148            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
149        return form_fields
150
151
152class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
153    """Deliver a PDF slip of the context.
154    """
155
156    @property
157    def form_fields(self):
158        if self.context.is_postgrad:
159            form_fields = grok.AutoFields(
160                ICustomPGStudentClearance).omit('clearance_locked')
161        else:
162            form_fields = grok.AutoFields(
163                ICustomUGStudentClearance).omit('clearance_locked')
164        if not getattr(self.context, 'officer_comment'):
165            form_fields = form_fields.omit('officer_comment')
166        return form_fields
167
168
169class CustomStudentClearanceManageFormPage(
170    NigeriaStudentClearanceManageFormPage):
171    """ Page to edit student clearance data
172    """
173
174    @property
175    def form_fields(self):
176        if self.context.is_postgrad:
177            form_fields = grok.AutoFields(
178                ICustomPGStudentClearance).omit('clr_code')
179        else:
180            form_fields = grok.AutoFields(
181                ICustomUGStudentClearance).omit('clr_code')
182        return form_fields
183
184
185class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
186    """ View to edit student clearance data by student
187    """
188
189    def dataNotComplete(self):
190        return False
191
192    @property
193    def form_fields(self):
194        if self.context.is_postgrad:
195            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
196            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
197            'physical_clearance_date')
198        else:
199            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
200            'clearance_locked', 'clr_code', 'officer_comment',
201            'physical_clearance_date')
202        return form_fields
203
204
205class BedTicketAddPage(BedTicketAddPage):
206    """ Page to add an online payment ticket
207    """
208    buttonname = _('Create bed ticket')
209    notice = ''
210    with_ac = False
211
212
213class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
214    """Deliver a PDF Admission slip.
215    """
216    grok.context(ICustomStudent)
217
218    omit_fields = ('date_of_birth', 'current_level')
219
220    form_fields = grok.AutoFields(ICustomStudent).select(
221        'student_id', 'reg_number')
222
223    @property
224    def label(self):
225        line0 = 'Registration Bio Data - B'
226        line1 = 'Admission Letter of %s' % self.context.display_fullname
227        return '%s\n%s' % (line0, line1)
228
229    def render(self):
230        if self.context.state in (CREATED, ADMITTED,
231                                  CLEARANCE, REQUESTED, CLEARED):
232            self.flash('Not allowed.')
233            self.redirect(self.url(self.context))
234            return
235        students_utils = getUtility(IStudentsUtils)
236        return students_utils.renderPDFAdmissionLetter(self,
237            self.context.student, omit_fields=self.omit_fields)
238
239
240class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
241    """Deliver a PDF Admission notification slip.
242    """
243    grok.context(ICustomStudent)
244    grok.name('admission_notification.pdf')
245    grok.require('waeup.viewStudent')
246    prefix = 'form'
247    label = 'Registration Bio Data - A\nNotification of Provisional Admission'
248
249    omit_fields = ('date_of_birth', 'current_level')
250
251    form_fields = grok.AutoFields(ICustomStudent).select(
252        'student_id', 'reg_number', 'sex', 'lga')
253
254    def render(self):
255        if self.context.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
256            self.flash('Not allowed.')
257            self.redirect(self.url(self.context))
258            return
259        students_utils = getUtility(IStudentsUtils)
260        pre_text = ''
261        post_text = post_text_freshers
262        return students_utils.renderPDFAdmissionLetter(self,
263            self.context.student, omit_fields=self.omit_fields,
264            pre_text=pre_text, post_text=post_text)
265
266
267# copied from waeup.aaue
268class CustomExportPDFCourseRegistrationSlip(
269    NigeriaExportPDFCourseRegistrationSlip):
270    """Deliver a PDF slip of the context.
271    """
272    grok.context(ICustomStudentStudyLevel)
273    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
274        'level_session', 'level_verdict',
275        'validated_by', 'validation_date', 'gpa', 'level')
276
277    omit_fields = ('password', 'suspended', 'suspended_comment',
278        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
279        'department', 'current_mode', 'current_level')
280
281    @property
282    def title(self):
283        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
284        return translate(_('Credits Registered'), 'waeup.kofa',
285            target_language=portal_language)
286
287    def _signatures(self):
288        """Signatures as inserted at document bottom.
289
290        As Kwarapoly requires a fancy 'certificate' there, the pre-
291        and post-fields of signatures are quite large and unusual
292        here.
293
294        This is also a workaround, as we cannot easily insert text
295        with signature fields in documents using reportlab platypus.
296
297        The signature boxes we return here contain context infos
298        (therefore this has to be a method) and return the following
299        layout:
300
301            +-----------------------------------------+
302            | (Empty pre text)                        |
303            +-------------+---------------------------+
304            |Date         | Students Signature        |
305            +-------------+---------------------------+
306            | (Empty post text)                       |
307            +=========================================+
308            |            Certification                |
309            +-------------+---------------------------+
310            |Date         | Director Signature, etc.  |
311            +-------------+---------------------------+
312            |NOTE: This form is the ...               |
313            +-----------------------------------------+
314
315
316        """
317        return (
318            [
319                ('', _('Student\'s Signature'), ''),
320                ],
321            [((
322                    "<br/>"
323                    + "&nbsp;" * 70 +
324                    "<u><b><font size='14'>Certification</font></b></u><br/>"
325                    "<br/><b><i>"
326                    "This is to certify that "
327                    "<font size='13'>"
328                    + self.context.student.display_fullname +
329                    "</font>"
330                    " has paid the full School Fees, duly registered and "
331                    "therefore, is cleared to sit for examination in the "
332                    "courses listed above."
333                    "</i></b><br/><br/>"
334                    ),
335              "Institute Director\'s Signature and Official Stamp",
336              (
337                    "<b><u>NOTE:</u></b> This form is the property of "
338                    "Kwara State Polytechnic, it is not transferable "
339                    "and students must properly fill it, get it duly "
340                    "endorsed and present it before they can be admitted "
341                    "into Examination Venues."
342                    )), ]
343            )
344
345    def render(self):
346        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
347        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
348        Title = translate('Title', 'waeup.kofa',
349                          target_language=portal_language)
350        Cred = translate(
351            'Cred.', 'waeup.kofa', target_language=portal_language)
352        Score = translate('Score', 'waeup.kofa',
353                          target_language=portal_language)
354        Grade = translate('Grade', 'waeup.kofa',
355                          target_language=portal_language)
356        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
357            target_language=portal_language)
358        studentview = StudentBasePDFFormPage(self.context.student,
359            self.request, self.omit_fields)
360        students_utils = getUtility(IStudentsUtils)
361
362        tabledata = []
363        tableheader = []
364        for i in range(1, 7):
365            tabledata.append(sorted(
366                [value for value in self.context.values()
367                 if value.semester == i],
368                key=lambda value: str(value.semester) + value.code))
369            tableheader.append([(Code, 'code', 2.0),
370                               (Title, 'title', 7),
371                               (Cred, 'credits', 1.5),
372                               (Score, 'score', 1.4),
373                               (Grade, 'grade', 1.4),
374                               (Signature, 'dummy', 3),
375                               ])
376        topMargin = 1.5 + (self.label.count('\n') * 0.2)
377        return students_utils.renderPDF(
378            self, 'course_registration_slip.pdf',
379            self.context.student, studentview,
380            tableheader=tableheader,
381            tabledata=tabledata,
382            signatures=self._signatures(),
383            topMargin=topMargin,
384            omit_fields=self.omit_fields,
385            )
386
387
388class ExportPDFRegistrationSlip(grok.View):
389    """Deliver a PDF slip of the context.
390    """
391    grok.context(ICustomStudent)
392    grok.name('registration_slip.pdf')
393    grok.require('waeup.viewStudent')
394    prefix = 'form'
395    omit_fields = (
396        'suspended', 'phone',
397        'adm_code', 'suspended_comment', 'email',
398        'current_mode', 'matric_number', 'date_of_birth', 'current_level')
399    title = 'Clearance and Personal Data'
400    label = 'Registration Bio Data - C\nProfile Data Slip'
401
402    form_fields = grok.AutoFields(ICustomStudent).select(
403        'date_of_birth', 'lga', 'nationality',
404        'perm_address', 'corr_address',
405        'marit_stat', 'sponsor_name', 'sponsor_address',
406        )
407
408    def render(self):
409        if self.context.state in (CREATED, ADMITTED,
410                                  CLEARANCE, REQUESTED, CLEARED):
411            self.flash('Not allowed.')
412            self.redirect(self.url(self.context))
413            return
414        studentview = StudentBasePDFFormPage(self.context.student,
415            self.request, self.omit_fields)
416        students_utils = getUtility(IStudentsUtils)
417        return students_utils.renderPDF(
418            self, 'registration_slip.pdf',
419            self.context.student, studentview, signatures=None,
420            omit_fields=self.omit_fields,
421            note=post_text_registration)
422
423post_text_registration = """<br /><br />
424<strong>IMPORTANT NOTICE</strong>
425<br /><br />
426This registration slip must be supplied before attendance of lectures. Note that:
427<br /><br />
4281. All fees due must be paid in full.
429<br /><br />
4302. All information required must be available on the Registration Form.
431<br /><br />
4323. The Signature of all appropriate Polytechnic Authority must be obtained.
433<br /><br />
4344. The endorsed Registration Form should be returned to the respective
435   Institutes and Administrative Offices.
436<br /><br />
4375. No student may change his subject or course of study as shown in the
438   signed Registration Form without clearance from the Admissions Office
439   and the Director of the appropriate Institute.
440<br /><br />
4416. All candidates admitted into the HND I programmes should submit the
442   photocopies of their original certificates of ND and SSCE with scratch
443   card online for clearance latest a week after the admission is offered.
444   Failure to comply with this directive may lead to the forfeiture of
445   the admission.
446<br /><br />
447<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
448<img src="${signature_img_path}" valign="-30"
449     height="75" width="172" />
450<br />
451M.O. Adebayo<br />
452Admission Officer<br />
453For: Registrar
454"""
455
456post_text_freshers = """
457<strong>INSTRUCTIONS TO FRESHERS</strong>
458<br /><br />
459You are hereby offered a provisional admission for the current academic
460 session subject to the conditions that:
461<br /><br />
4621. The information given in your Application Form is correct.
463<br /><br />
4642. The original of your Credentials are presented for scrutiny.
465<br /><br />
4663. If at any time the Credentials submitted are found to be false/fake
467   or incorrect, your admission shall be withdrawn.
468<br /><br />
4694. The name by which you are admitted and registered shall remain same
470   throughout the duration of your programme.
471<br /><br />
4725. You are to fill and submit the Undertaking Form at the point of
473   registration failure which your admission will be forfeited.
474<br /><br />
4756. You will dress decently covering your nakedness at all times.
476<br /><br />
4777. Payment of school fees will be once and in full and should be by
478   Interswitch to the designated Banks. Failure to pay fees by the
479   mode mentioned above by the closing date means you have declined
480   the offer and your place will be given to another eligible
481   candidate immediately.
482<br /><br />
4838. You present a Certificate of medical fitness from the Polytechnic
484   Clinic.
485<br /><br />
4869. All indigenes of Kwara State are required to present Certificate of
487   Citizenship.
488<br /><br />
48910. The Polytechnic reserves the right to withdraw your admission at
490    any stage, if you are found to be a cultist or an expelled
491    individual from any tertiary institution. In addition, it should be
492    noted that the Polytechnic will not entertain any change of name
493    different from the one filled by the candidate on his/her Application
494    Form.
495<br /><br />
49611. You are prepared to take up accommodation provided on the campuses
497    by the authority.
498<br /><br />
49912. There will be no refund of school fees once paid.
500<br /><br />
50113. If you accept this offer with the above stated conditions, please
502    make a photocopy of this document and return it to the Admission
503    Office immediately.
504<br /><br />
50514. You possess the entry requirement for the programme you are admitted.
506<br /><br />
507
508<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
509<img src="${signature_img_path}" valign="-30"
510     height="75" width="172" />
511<br />
512M.O. Adebayo<br />
513Admission Officer<br />
514For: Registrar
515"""
516# XXX: a note for <img /> tag used here (from reportlab docs):
517#   The valign attribute may be set to a css like value from "baseline", "sub",
518#   "super", "top", "text-top", "middle", "bottom", "text-bottom";
519#   the value may also be a numeric percentage or an absolute value.
520#
521# Burn this remark after reading.
522
523
524class StudentGetMatricNumberView(UtilityView, grok.View):
525    """ Construct and set the matriculation number.
526    """
527    grok.context(ICustomStudent)
528    grok.name('get_matric_number')
529    grok.require('waeup.viewStudent')
530
531    def update(self):
532        students_utils = getUtility(IStudentsUtils)
533        msg, mnumber = students_utils.setMatricNumber(self.context)
534        if msg:
535            self.flash(msg, type="danger")
536        else:
537            self.flash(_('Matriculation number %s assigned.' % mnumber))
538            self.context.writeLogMessage(self, '%s assigned' % mnumber)
539        self.redirect(self.url(self.context))
540        return
541
542    def render(self):
543        return
Note: See TracBrowser for help on using the repository browser.