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

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

Rename 'Study Course', 'Phone', 'Email', 'Faculty'.

Edit text on slips.

  • Property svn:keywords set to Id
File size: 16.4 KB
Line 
1## $Id: browser.py 11873 2014-10-22 14:11:24Z 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 hurry.workflow.interfaces import IWorkflowInfo
23from waeup.kofa.interfaces import ADMITTED, 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, ExportPDFAdmissionSlipPage,
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    NigeriaExportPDFPaymentSlipPage,
41    NigeriaStudentClearanceDisplayFormPage,
42    NigeriaExportPDFClearanceSlipPage,
43    NigeriaStudentClearanceEditFormPage,
44    NigeriaExportPDFCourseRegistrationSlipPage,
45    NigeriaStudentPersonalDisplayFormPage,
46    NigeriaStudentClearanceManageFormPage,
47    NigeriaStudentPersonalEditFormPage,
48    NigeriaStudentPersonalManageFormPage,
49    NigeriaStudentBaseEditFormPage
50    )
51
52from waeup.kwarapoly.students.interfaces import (
53    ICustomStudentOnlinePayment,
54    ICustomStudentPersonal,
55    ICustomStudentPersonalEdit
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
64class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage):
65    """ Page to display student personal data
66    """
67    form_fields = grok.AutoFields(ICustomStudentPersonal)
68    form_fields['perm_address'].custom_widget = BytesDisplayWidget
69    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
70    form_fields['corr_address'].custom_widget = BytesDisplayWidget
71    form_fields['sponsor_address'].custom_widget = BytesDisplayWidget
72    form_fields[
73        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
74
75class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
76    """ Page to edit personal data
77    """
78    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit(
79        'personal_updated')
80
81class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage):
82    """ Page to edit personal data
83    """
84    form_fields = grok.AutoFields(ICustomStudentPersonal)
85    form_fields['personal_updated'].for_display = True
86    form_fields[
87        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
88
89class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
90    """ Page to view an online payment ticket
91    """
92    grok.context(ICustomStudentOnlinePayment)
93    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
94        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
95    form_fields[
96        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
97    form_fields[
98        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
99
100class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
101    """ Page to add an online payment ticket
102    """
103    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
104        'p_category')
105
106class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
107    """Deliver a PDF slip of the context.
108    """
109    grok.context(ICustomStudentOnlinePayment)
110    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
111        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
112    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
114
115class CustomStartClearancePage(StartClearancePage):
116
117    with_ac = False
118
119
120class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage):
121    """ Page to display student clearance data
122    """
123
124    @property
125    def form_fields(self):
126        if self.context.is_postgrad:
127            form_fields = grok.AutoFields(
128                ICustomPGStudentClearance).omit('clearance_locked')
129        else:
130            form_fields = grok.AutoFields(
131                ICustomUGStudentClearance).omit('clearance_locked')
132        if not getattr(self.context, 'officer_comment'):
133            form_fields = form_fields.omit('officer_comment')
134        else:
135            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
136        return form_fields
137
138class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
139    """Deliver a PDF slip of the context.
140    """
141
142    @property
143    def form_fields(self):
144        if self.context.is_postgrad:
145            form_fields = grok.AutoFields(
146                ICustomPGStudentClearance).omit('clearance_locked')
147        else:
148            form_fields = grok.AutoFields(
149                ICustomUGStudentClearance).omit('clearance_locked')
150        if not getattr(self.context, 'officer_comment'):
151            form_fields = form_fields.omit('officer_comment')
152        return form_fields
153
154class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage):
155    """ Page to edit student clearance data
156    """
157
158    @property
159    def form_fields(self):
160        if self.context.is_postgrad:
161            form_fields = grok.AutoFields(
162                ICustomPGStudentClearance).omit('clr_code')
163        else:
164            form_fields = grok.AutoFields(
165                ICustomUGStudentClearance).omit('clr_code')
166        return form_fields
167
168class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
169    """ View to edit student clearance data by student
170    """
171
172    def dataNotComplete(self):
173        return False
174
175    @property
176    def form_fields(self):
177        if self.context.is_postgrad:
178            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
179            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment')
180        else:
181            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
182            'clearance_locked', 'clr_code', 'officer_comment')
183        return form_fields
184
185class BedTicketAddPage(BedTicketAddPage):
186    """ Page to add an online payment ticket
187    """
188    buttonname = _('Create bed ticket')
189    notice = ''
190    with_ac = False
191
192class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
193    """Deliver a PDF Admission slip.
194    """
195    grok.context(ICustomStudent)
196
197    omit_fields = ('date_of_birth', 'current_level')
198
199    form_fields = grok.AutoFields(ICustomStudent).select('student_id', 'reg_number')
200
201    def render(self):
202        if self.context.state in (CREATED, ADMITTED,
203                                  CLEARANCE, REQUESTED, CLEARED):
204            self.flash('Not allowed.')
205            self.redirect(self.url(self.context))
206            return
207        students_utils = getUtility(IStudentsUtils)
208        return students_utils.renderPDFAdmissionLetter(self,
209            self.context.student, omit_fields=self.omit_fields)
210
211class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
212    """Deliver a PDF Admission notification slip.
213    """
214    grok.context(ICustomStudent)
215    grok.name('admission_notification.pdf')
216    grok.require('waeup.viewStudent')
217    prefix = 'form'
218    label = 'Notification of Provisional Admission'
219
220    omit_fields = ('date_of_birth', 'current_level')
221
222    form_fields = grok.AutoFields(ICustomStudent).select(
223        'student_id', 'reg_number', 'sex', 'lga')
224
225    def render(self):
226        if self.context.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
227            self.flash('Not allowed.')
228            self.redirect(self.url(self.context))
229            return
230        students_utils = getUtility(IStudentsUtils)
231        pre_text = ''
232        post_text = post_text_freshers
233        return students_utils.renderPDFAdmissionLetter(self,
234            self.context.student, omit_fields=self.omit_fields,
235            pre_text=pre_text, post_text=post_text)
236
237# copied from waeup.aaue
238class CustomExportPDFCourseRegistrationSlipPage(
239    NigeriaExportPDFCourseRegistrationSlipPage):
240    """Deliver a PDF slip of the context.
241    """
242    grok.context(ICustomStudentStudyLevel)
243    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
244        'level_session', 'level_verdict',
245        'validated_by', 'validation_date', 'gpa')
246
247    omit_fields = ('password', 'suspended', 'suspended_comment',
248        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
249        'department', 'current_mode', 'current_level')
250
251    @property
252    def title(self):
253        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
254        return translate(_('Credits Registered'), 'waeup.kofa',
255            target_language=portal_language)
256
257    def _signatures(self):
258        return (
259            [('I have selected the course on the advise of my Head of '
260             'Department. <br>', _('Student\'s Signature'), '<br>')],
261            [('This student has satisfied the department\'s requirements. '
262             'I recommend to approve the course registration. <br>',
263             _('Head of Department\'s Signature'), '<br>')],
264            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
265            [('', _('Director\'s Signature'))]
266            )
267
268    def render(self):
269        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
270        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
271        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
272        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
273        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
274        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
275        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
276        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
277            target_language=portal_language)
278        studentview = StudentBasePDFFormPage(self.context.student,
279            self.request, self.omit_fields)
280        students_utils = getUtility(IStudentsUtils)
281
282        tabledata = []
283        tableheader = []
284        contenttitle = []
285        for i in range(1,7):
286            tabledata.append(sorted(
287                [value for value in self.context.values() if value.semester == i],
288                key=lambda value: str(value.semester) + value.code))
289            tableheader.append([(Code,'code', 2.0),
290                               (Title,'title', 7),
291                               (Cred, 'credits', 1.5),
292                               (Score, 'score', 1.4),
293                               (Grade, 'grade', 1.4),
294                               (Signature, 'dummy', 3),
295                               ])
296        if len(self.label.split('\n')) == 3:
297            topMargin = 1.9
298        elif len(self.label.split('\n')) == 2:
299            topMargin = 1.7
300        else:
301            topMargin = 1.5
302        return students_utils.renderPDF(
303            self, 'course_registration_slip.pdf',
304            self.context.student, studentview,
305            tableheader=tableheader,
306            tabledata=tabledata,
307            signatures=self._signatures(),
308            topMargin=topMargin,
309            omit_fields=self.omit_fields
310            )
311
312class ExportPDFRegistrationSlipPage(grok.View):
313    """Deliver a PDF slip of the context.
314    """
315    grok.context(ICustomStudent)
316    grok.name('registration_slip.pdf')
317    grok.require('waeup.viewStudent')
318    prefix = 'form'
319    omit_fields = (
320        'suspended', 'phone',
321        'adm_code', 'suspended_comment', 'email',
322        'current_mode', 'matric_number', 'date_of_birth', 'current_level')
323    title = 'Clearance and Personal Data'
324    label = 'Profile Registration Slip'
325
326    form_fields = grok.AutoFields(ICustomStudent).select(
327        'date_of_birth', 'lga', 'nationality',
328        'perm_address', 'corr_address',
329        'marit_stat', 'sponsor_name', 'sponsor_address',
330        )
331
332    def render(self):
333        studentview = StudentBasePDFFormPage(self.context.student,
334            self.request, self.omit_fields)
335        students_utils = getUtility(IStudentsUtils)
336        return students_utils.renderPDF(
337            self, 'registration_slip.pdf',
338            self.context.student, studentview, signatures=None,
339            omit_fields=self.omit_fields,
340            note=post_text_registration)
341
342post_text_registration = """<br /><br />
343<strong>IMPORTANT NOTICE</strong>
344<br /><br />
345This registration slip must be supplied before attendance of lectures. Note that:<br /><br />
3461. All fees due must be paid in full.<br /><br />
3472. All information required must be available on the Registration Form.<br /><br />
3483. The Signature of all appropriate Polytechnic Authority must be obtained.<br /><br />
3494. The endorsed Registration Form should be returned to the respective Institutes and Administrative Offices.<br /><br />
3505. No student may change his subject or course of study as shown in the signed Registration Form without clearance from the Admissions Office and the Director of the appropriate Institute.<br /><br />
3516. All candidates admitted into the HND I programmes should submit the photocopies of their original certificates of ND and SSCE with scratch card online for clearance latest a week after the admission is offered. Failure to comply with this directive may lead to the forfeiture of the admission.<br /><br />
352
353M.O. Adebayo<br />
354Admission Officer<br />
355For: Registrar
356"""
357
358post_text_freshers = """
359<strong>INSTRUCTIONS TO FRESHERS</strong>
360<br /><br />
361You are hereby offered a provisional admission for the 2014/2015 session subject to the conditions that:
362<br /><br />
3631. The information given in your Application Form is correct.<br /><br />
3642. The original of your Credentials are presented for scrutiny.<br /><br />
3653. If at any time the Credentials submitted are found to be false/fake or incorrect, your admission shall be withdrawn.<br /><br />
3664. The name by which you are admitted and registered shall remain same throughout the duration of your programme.<br /><br />
3675. You are to fill and submit the Undertaking Form at the point of registration failure which your admission will be forfeited.<br /><br />
3686. You will dress decently covering your nakedness at all times.<br /><br />
3697. Payment of school fees will be once and in full and should be by Interswitch to the designated Banks. Failure to pay fees by the mode mentioned above by the closing date means you have declined the offer and your place will be given to another eligible candidate immediately.<br /><br />
3708. You present a Certificate of medical fitness from the Polytechnic Clinic.<br /><br />
3719. All indigenes of Kwara State are required to present Certificate of Citizenship.<br /><br />
37210. The Polytechnic reserves the right to withdraw your admission at any stage, if you are found to be a cultist or an expelled individual from any tertiary institution.<br /><br />
37311. You are prepared to take up accommodation provided on the campuses by the authority.<br /><br />
37412. There will be no refund of school fees once paid.<br /><br />
37513. If you accept this offer with the above stated conditions, please make a photocopy of this document and return it to the Admission Office immediately.<br /><br />
37614. You possess the entry requirement for the programme you are admitted.<br /><br />
377
378M.O. Adebayo<br />
379Admission Officer<br />
380For: Registrar
381"""
Note: See TracBrowser for help on using the repository browser.