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

Last change on this file since 12379 was 12149, checked in by Henrik Bettermann, 10 years ago

Breaking a line leads to missing spaces on pdf slips.

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