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

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

Make registration slip download available to new students only after
they have paid their fees.

  • Property svn:keywords set to Id
File size: 19.0 KB
RevLine 
[8911]1## $Id: browser.py 11931 2014-11-02 06:54:31Z 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
[10710]20from zope.formlib.textwidgets import BytesDisplayWidget
[10691]21from zope.component import getUtility
[11906]22from waeup.kofa.interfaces import IKofaUtils
[10691]23from waeup.kofa.browser.layout import UtilityView
24from waeup.kofa.students.interfaces import IStudentsUtils
[8911]25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[10691]26from waeup.kofa.students.browser import (
[10692]27    StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage,
28    StudentBasePDFFormPage)
[10691]29from waeup.kwarapoly.students.interfaces import (
[11864]30    ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel,
31    ICustomUGStudentClearance, ICustomPGStudentClearance)
[10691]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)
[8911]36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
38    NigeriaOnlinePaymentAddFormPage,
[9181]39    NigeriaExportPDFPaymentSlipPage,
[11864]40    NigeriaStudentClearanceDisplayFormPage,
41    NigeriaExportPDFClearanceSlipPage,
[9190]42    NigeriaStudentClearanceEditFormPage,
[10692]43    NigeriaExportPDFCourseRegistrationSlipPage,
[10710]44    NigeriaStudentPersonalDisplayFormPage,
[11864]45    NigeriaStudentClearanceManageFormPage,
[10710]46    NigeriaStudentPersonalEditFormPage,
[10819]47    NigeriaStudentPersonalManageFormPage,
48    NigeriaStudentBaseEditFormPage
[9190]49    )
[8911]50
[10710]51from waeup.kwarapoly.students.interfaces import (
52    ICustomStudentOnlinePayment,
53    ICustomStudentPersonal,
54    ICustomStudentPersonalEdit
55    )
[8911]56
[11887]57
[10819]58class CustomStudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
59    """ View to edit student base data
60    """
61    form_fields = grok.AutoFields(ICustomStudentBase).select(
62        'email', 'phone', 'sex')
63
[11887]64
65class CustomStudentPersonalDisplayFormPage(
66    NigeriaStudentPersonalDisplayFormPage):
[10710]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
[11887]77
[10710]78class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
79    """ Page to edit personal data
80    """
81    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit(
82        'personal_updated')
83
[11887]84
85class CustomStudentPersonalManageFormPage(
86    NigeriaStudentPersonalManageFormPage):
[10710]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
[11887]94
[8911]95class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
96    """ Page to view an online payment ticket
97    """
98    grok.context(ICustomStudentOnlinePayment)
[9789]99    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9992]100        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]101    form_fields[
102        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
103    form_fields[
104        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
105
[11887]106
[8911]107class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
108    """ Page to add an online payment ticket
109    """
110    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
111        'p_category')
112
[11887]113
[8911]114class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
115    """Deliver a PDF slip of the context.
116    """
117    grok.context(ICustomStudentOnlinePayment)
[9789]118    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9992]119        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[11887]120    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget(
121        'le')
122    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget(
123        'le')
[9156]124
[11887]125
[9156]126class CustomStartClearancePage(StartClearancePage):
127
[9955]128    with_ac = False
[9156]129
[11864]130
[11887]131class CustomStudentClearanceDisplayFormPage(
132    NigeriaStudentClearanceDisplayFormPage):
[11864]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
[11887]150
[11864]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
[11887]167
168class CustomStudentClearanceManageFormPage(
169    NigeriaStudentClearanceManageFormPage):
[11864]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
[11887]183
[9181]184class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
185    """ View to edit student clearance data by student
186    """
187
188    def dataNotComplete(self):
[9190]189        return False
190
[11864]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
[11887]201
[9190]202class BedTicketAddPage(BedTicketAddPage):
203    """ Page to add an online payment ticket
204    """
205    buttonname = _('Create bed ticket')
206    notice = ''
[10691]207    with_ac = False
208
[11887]209
[10691]210class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
211    """Deliver a PDF Admission slip.
212    """
213    grok.context(ICustomStudent)
214
[11539]215    omit_fields = ('date_of_birth', 'current_level')
[10691]216
[11887]217    form_fields = grok.AutoFields(ICustomStudent).select(
218        'student_id', 'reg_number')
[10691]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
[11887]230
[10691]231class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
[11873]232    """Deliver a PDF Admission notification slip.
[10691]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
[11539]240    omit_fields = ('date_of_birth', 'current_level')
[10691]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 = ''
[10703]252        post_text = post_text_freshers
[10691]253        return students_utils.renderPDFAdmissionLetter(self,
254            self.context.student, omit_fields=self.omit_fields,
255            pre_text=pre_text, post_text=post_text)
[10692]256
[11887]257
[10692]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',
[11539]270        'department', 'current_mode', 'current_level')
[10692]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):
[11901]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        """
[10692]308        return (
[11901]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 "
[11903]322                    "therefore, is cleared to sit for examination in the "
[11901]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."
[11905]333                    )), ]
[10692]334            )
335
336    def render(self):
337        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
338        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
[11887]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)
[10692]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 = []
[11887]355        for i in range(1, 7):
[10692]356            tabledata.append(sorted(
[11887]357                [value for value in self.context.values()
358                 if value.semester == i],
[10692]359                key=lambda value: str(value.semester) + value.code))
[11887]360            tableheader.append([(Code, 'code', 2.0),
361                               (Title, 'title', 7),
[10692]362                               (Cred, 'credits', 1.5),
363                               (Score, 'score', 1.4),
364                               (Grade, 'grade', 1.4),
365                               (Signature, 'dummy', 3),
366                               ])
[11901]367        topMargin = 1.5 + (self.label.count('\n') * 0.2)
[10692]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,
[11901]375            omit_fields=self.omit_fields,
[10695]376            )
377
[11887]378
[10695]379class ExportPDFRegistrationSlipPage(grok.View):
380    """Deliver a PDF slip of the context.
381    """
382    grok.context(ICustomStudent)
[10705]383    grok.name('registration_slip.pdf')
[10695]384    grok.require('waeup.viewStudent')
385    prefix = 'form'
386    omit_fields = (
387        'suspended', 'phone',
[10705]388        'adm_code', 'suspended_comment', 'email',
[11539]389        'current_mode', 'matric_number', 'date_of_birth', 'current_level')
[10705]390    title = 'Clearance and Personal Data'
391    label = 'Profile Registration Slip'
[10695]392
393    form_fields = grok.AutoFields(ICustomStudent).select(
[10705]394        'date_of_birth', 'lga', 'nationality',
395        'perm_address', 'corr_address',
396        'marit_stat', 'sponsor_name', 'sponsor_address',
397        )
[10695]398
399    def render(self):
[11931]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
[10695]405        studentview = StudentBasePDFFormPage(self.context.student,
406            self.request, self.omit_fields)
407        students_utils = getUtility(IStudentsUtils)
408        return students_utils.renderPDF(
[10705]409            self, 'registration_slip.pdf',
[11873]410            self.context.student, studentview, signatures=None,
[10703]411            omit_fields=self.omit_fields,
412            note=post_text_registration)
413
[11873]414post_text_registration = """<br /><br />
415<strong>IMPORTANT NOTICE</strong>
[10703]416<br /><br />
[11887]417This registration slip must be supplied before attendance of lectures.
418Note that:
419<br /><br />
4201. All fees due must be paid in full.
421<br /><br />
4222. All information required must be available on the Registration Form.
423<br /><br />
4243. The Signature of all appropriate Polytechnic Authority must be obtained.
425<br /><br />
4264. The endorsed Registration Form should be returned to the respective
427   Institutes and Administrative Offices.
428<br /><br />
4295. No student may change his subject or course of study as shown in the
430   signed Registration Form without clearance from the Admissions Office
431   and the Director of the appropriate Institute.
432<br /><br />
4336. All candidates admitted into the HND I programmes should submit the
434   photocopies of their original certificates of ND and SSCE with scratch
435   card online for clearance latest a week after the admission is offered.
436   Failure to comply with this directive may lead to the forfeiture of
437   the admission.
438<br /><br />
439<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
440<img src="${signature_img_path}" valign="-30"
441     height="75" width="172" />
442<br />
[11873]443M.O. Adebayo<br />
444Admission Officer<br />
445For: Registrar
[10703]446"""
447
448post_text_freshers = """
449<strong>INSTRUCTIONS TO FRESHERS</strong>
450<br /><br />
[11887]451You are hereby offered a provisional admission for the 2014/2015 session
452subject to the conditions that:
[10703]453<br /><br />
[11887]4541. The information given in your Application Form is correct.
455<br /><br />
4562. The original of your Credentials are presented for scrutiny.
457<br /><br />
4583. If at any time the Credentials submitted are found to be false/fake
459   or incorrect, your admission shall be withdrawn.
460<br /><br />
4614. The name by which you are admitted and registered shall remain same
462   throughout the duration of your programme.
463<br /><br />
4645. You are to fill and submit the Undertaking Form at the point of
465   registration failure which your admission will be forfeited.
466<br /><br />
4676. You will dress decently covering your nakedness at all times.
468<br /><br />
4697. Payment of school fees will be once and in full and should be by
470   Interswitch to the designated Banks. Failure to pay fees by the
471   mode mentioned above by the closing date means you have declined
472   the offer and your place will be given to another eligible
473   candidate immediately.
474<br /><br />
4758. You present a Certificate of medical fitness from the Polytechnic
476   Clinic.
477<br /><br />
4789. All indigenes of Kwara State are required to present Certificate of
479   Citizenship.
480<br /><br />
48110. The Polytechnic reserves the right to withdraw your admission at
482    any stage, if you are found to be a cultist or an expelled
483    individual from any tertiary institution.
484<br /><br />
48511. You are prepared to take up accommodation provided on the campuses
486    by the authority.
487<br /><br />
48812. There will be no refund of school fees once paid.
489<br /><br />
49013. If you accept this offer with the above stated conditions, please
491    make a photocopy of this document and return it to the Admission
492    Office immediately.
493<br /><br />
49414. You possess the entry requirement for the programme you are admitted.
495<br /><br />
[11873]496
[11887]497<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
498<img src="${signature_img_path}" valign="-30"
499     height="75" width="172" />
500<br />
[11873]501M.O. Adebayo<br />
502Admission Officer<br />
503For: Registrar
[11887]504"""
505# XXX: a note for <img /> tag used here (from reportlab docs):
506#   The valign attribute may be set to a css like value from "baseline", "sub",
507#   "super", "top", "text-top", "middle", "bottom", "text-bottom";
508#   the value may also be a numeric percentage or an absolute value.
509#
510# Burn this remark after reading.
Note: See TracBrowser for help on using the repository browser.