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

Last change on this file since 10819 was 10819, checked in by Henrik Bettermann, 11 years ago

Add sex field to edit form page.

  • Property svn:keywords set to Id
File size: 13.7 KB
Line 
1## $Id: browser.py 10819 2013-11-29 13:44:55Z 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)
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    NigeriaStudentClearanceEditFormPage,
41    NigeriaExportPDFCourseRegistrationSlipPage,
42    NigeriaStudentPersonalDisplayFormPage,
43    NigeriaStudentPersonalEditFormPage,
44    NigeriaStudentPersonalManageFormPage,
45    NigeriaStudentBaseEditFormPage
46    )
47
48from waeup.kwarapoly.students.interfaces import (
49    ICustomStudentOnlinePayment,
50    ICustomStudentPersonal,
51    ICustomStudentPersonalEdit
52    )
53
54class CustomStudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
55    """ View to edit student base data
56    """
57    form_fields = grok.AutoFields(ICustomStudentBase).select(
58        'email', 'phone', 'sex')
59
60class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage):
61    """ Page to display student personal data
62    """
63    form_fields = grok.AutoFields(ICustomStudentPersonal)
64    form_fields['perm_address'].custom_widget = BytesDisplayWidget
65    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
66    form_fields['corr_address'].custom_widget = BytesDisplayWidget
67    form_fields['sponsor_address'].custom_widget = BytesDisplayWidget
68    form_fields[
69        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
70
71class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
72    """ Page to edit personal data
73    """
74    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit(
75        'personal_updated')
76
77class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage):
78    """ Page to edit personal data
79    """
80    form_fields = grok.AutoFields(ICustomStudentPersonal)
81    form_fields['personal_updated'].for_display = True
82    form_fields[
83        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
84
85class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
86    """ Page to view an online payment ticket
87    """
88    grok.context(ICustomStudentOnlinePayment)
89    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
90        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
91    form_fields[
92        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
93    form_fields[
94        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
95
96class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
97    """ Page to add an online payment ticket
98    """
99    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
100        'p_category')
101
102class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
103    """Deliver a PDF slip of the context.
104    """
105    grok.context(ICustomStudentOnlinePayment)
106    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
107        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
108    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
109    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
110
111class CustomStartClearancePage(StartClearancePage):
112
113    with_ac = False
114
115class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
116    """ View to edit student clearance data by student
117    """
118
119    def dataNotComplete(self):
120        return False
121
122class BedTicketAddPage(BedTicketAddPage):
123    """ Page to add an online payment ticket
124    """
125    buttonname = _('Create bed ticket')
126    notice = ''
127    with_ac = False
128
129class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
130    """Deliver a PDF Admission slip.
131    """
132    grok.context(ICustomStudent)
133
134    omit_fields = ('date_of_birth',)
135
136    form_fields = grok.AutoFields(ICustomStudent).select('student_id', 'reg_number')
137
138    def render(self):
139        if self.context.state in (CREATED, ADMITTED,
140                                  CLEARANCE, REQUESTED, CLEARED):
141            self.flash('Not allowed.')
142            self.redirect(self.url(self.context))
143            return
144        students_utils = getUtility(IStudentsUtils)
145        return students_utils.renderPDFAdmissionLetter(self,
146            self.context.student, omit_fields=self.omit_fields)
147
148class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
149    """Deliver a PDF Admission nostification slip.
150    """
151    grok.context(ICustomStudent)
152    grok.name('admission_notification.pdf')
153    grok.require('waeup.viewStudent')
154    prefix = 'form'
155    label = 'Notification of Provisional Admission'
156
157    omit_fields = ('date_of_birth',)
158
159    form_fields = grok.AutoFields(ICustomStudent).select(
160        'student_id', 'reg_number', 'sex', 'lga')
161
162    def render(self):
163        if self.context.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
164            self.flash('Not allowed.')
165            self.redirect(self.url(self.context))
166            return
167        students_utils = getUtility(IStudentsUtils)
168        pre_text = ''
169        post_text = post_text_freshers
170        return students_utils.renderPDFAdmissionLetter(self,
171            self.context.student, omit_fields=self.omit_fields,
172            pre_text=pre_text, post_text=post_text)
173
174# copied from waeup.aaue
175class CustomExportPDFCourseRegistrationSlipPage(
176    NigeriaExportPDFCourseRegistrationSlipPage):
177    """Deliver a PDF slip of the context.
178    """
179    grok.context(ICustomStudentStudyLevel)
180    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
181        'level_session', 'level_verdict',
182        'validated_by', 'validation_date', 'gpa')
183
184    omit_fields = ('password', 'suspended', 'suspended_comment',
185        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
186        'department', 'current_mode')
187
188    @property
189    def title(self):
190        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
191        return translate(_('Credits Registered'), 'waeup.kofa',
192            target_language=portal_language)
193
194    def _signatures(self):
195        return (
196            [('I have selected the course on the advise of my Head of '
197             'Department. <br>', _('Student\'s Signature'), '<br>')],
198            [('This student has satisfied the department\'s requirements. '
199             'I recommend to approve the course registration. <br>',
200             _('Head of Department\'s Signature'), '<br>')],
201            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
202            [('', _('Director\'s Signature'))]
203            )
204
205    def render(self):
206        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
207        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
208        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
209        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
210        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
211        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
212        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
213        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
214            target_language=portal_language)
215        studentview = StudentBasePDFFormPage(self.context.student,
216            self.request, self.omit_fields)
217        students_utils = getUtility(IStudentsUtils)
218
219        tabledata = []
220        tableheader = []
221        contenttitle = []
222        for i in range(1,7):
223            tabledata.append(sorted(
224                [value for value in self.context.values() if value.semester == i],
225                key=lambda value: str(value.semester) + value.code))
226            tableheader.append([(Code,'code', 2.0),
227                               (Title,'title', 7),
228                               (Cred, 'credits', 1.5),
229                               (Score, 'score', 1.4),
230                               (Grade, 'grade', 1.4),
231                               (Signature, 'dummy', 3),
232                               ])
233        if len(self.label.split('\n')) == 3:
234            topMargin = 1.9
235        elif len(self.label.split('\n')) == 2:
236            topMargin = 1.7
237        else:
238            topMargin = 1.5
239        return students_utils.renderPDF(
240            self, 'course_registration_slip.pdf',
241            self.context.student, studentview,
242            tableheader=tableheader,
243            tabledata=tabledata,
244            signatures=self._signatures(),
245            topMargin=topMargin,
246            omit_fields=self.omit_fields
247            )
248
249class ExportPDFRegistrationSlipPage(grok.View):
250    """Deliver a PDF slip of the context.
251    """
252    grok.context(ICustomStudent)
253    grok.name('registration_slip.pdf')
254    grok.require('waeup.viewStudent')
255    prefix = 'form'
256    omit_fields = (
257        'suspended', 'phone',
258        'adm_code', 'suspended_comment', 'email',
259        'current_mode', 'matric_number', 'date_of_birth')
260    title = 'Clearance and Personal Data'
261    label = 'Profile Registration Slip'
262
263    form_fields = grok.AutoFields(ICustomStudent).select(
264        'date_of_birth', 'lga', 'nationality',
265        'perm_address', 'corr_address',
266        'marit_stat', 'sponsor_name', 'sponsor_address',
267        )
268
269    def render(self):
270        studentview = StudentBasePDFFormPage(self.context.student,
271            self.request, self.omit_fields)
272        students_utils = getUtility(IStudentsUtils)
273        return students_utils.renderPDF(
274            self, 'registration_slip.pdf',
275            self.context.student, studentview, signatures=([_('Bursar')],),
276            omit_fields=self.omit_fields,
277            note=post_text_registration)
278
279post_text_registration = """<br /><br /><br /><br />
280<strong>IMPORTANTANT NOTICE</strong>
281<br /><br />
282This registration slip must be submitted before attendance of lectures. Note that:<br /><br />
2831. All fees due must be paid in full.<br /><br />
2842. All information required must be available on the Registration Form.<br /><br />
2853. The Signature of all appropriate Polytechnic Authority must be obtained.<br /><br />
2864. The endorsed Registration Form should be returned to the respective Institutes and Administrative Offices.<br /><br />
2875. No student may change his subject or course of study as shown in the signed Registration Form without clearance from Admissions Office and the Director of the appropriate Institute.
288"""
289
290post_text_freshers = """
291<strong>INSTRUCTIONS TO FRESHERS</strong>
292<br /><br />
293You are hereby offered a provisional admission for the 2013/2014 session subject to the conditions that:
294<br /><br />
2951. The information given in your Application Form is correct.<br /><br />
2962. The original of your Credentials are presented for scrutiny.<br /><br />
2973. If at any time the Credentials submitted are found to be false/fake or incorrect, your admission shall be withdrawn.<br /><br />
2984. The name by which you are admitted and registered shall remain same throughout the duration of your programme.<br /><br />
2995. You are to fill and submit the Undertaking Form at the point of registration failure which your admission will be forfeited.<br /><br />
3006. You will dress decently covering your nakedness at all times.<br /><br />
3017. 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 />
3028. You present a Certificate of medical fitness from the Polytechnic Clinic.<br /><br />
3039. All indigenes of Kwara State are required to present Certificate of Citizenship.<br /><br />
30410. 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 />
30511. You are prepared to take up accommodation provided on the campuses by the authority.<br /><br />
30612. There will be no refund of school fees once paid.<br /><br />
30713. If you accept this offer with above stated conditions, please make a photocopy of this document and return it to the Admission Office immediately.<br /><br />
30814. You possess the entry requirement for the programme you are admitted into before making payment of school fees and registration.<br /><br />
309"""
Note: See TracBrowser for help on using the repository browser.