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

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

Not all documents are required.

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