source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py @ 18260

Last change on this file since 18260 was 18260, checked in by Henrik Bettermann, 7 months ago

Activate course_category field.

  • Property svn:keywords set to Id
File size: 16.4 KB
Line 
1## $Id: browser.py 18260 2026-04-29 07:51:53Z 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
19import os
20from zope.i18n import translate
21from zope.component import getUtility
22from zope.security import checkPermission
23from hurry.workflow.interfaces import IWorkflowInfo
24from waeup.kofa.interfaces import ADMITTED, VALIDATED, IKofaUtils
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
27from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
28from waeup.kofa.students.browser import (
29    StartClearancePage,
30    ExportPDFAdmissionSlip,
31    PaymentsManageFormPage,
32    OnlinePaymentApproveView,
33    CourseTicketDisplayFormPage,
34    CourseTicketManageFormPage,
35    StudentBasePDFFormPage,
36    StudyLevelDisplayFormPage,
37    StudyLevelManageFormPage,
38    StudyLevelEditFormPage)
39from kofacustom.nigeria.students.browser import (
40    NigeriaOnlinePaymentDisplayFormPage,
41    NigeriaOnlinePaymentAddFormPage,
42    NigeriaExportPDFPaymentSlip,
43    NigeriaStudentClearanceDisplayFormPage,
44    NigeriaStudentClearanceEditFormPage,
45    NigeriaStudentClearanceManageFormPage,
46    NigeriaExportPDFClearanceSlip,
47    NigeriaExportPDFCourseRegistrationSlip,
48    NigeriaBedTicketAddPage,
49    NigeriaAccommodationManageFormPage,
50    NigeriaAccommodationDisplayFormPage,
51    )
52
53from waeup.fceokene.students.interfaces import (
54    ICustomStudentOnlinePayment,
55    ICustomUGStudentClearance,
56    ICustomPGStudentClearance,
57    ICustomStudentStudyLevel)
58
59class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
60    """Deliver a PDF Admission slip.
61    """
62
63    @property
64    def label(self):
65        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
66        line0 = ''
67        if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP':
68            line0 = 'IN AFFILIATION WITH UNIVERSITY OF IBADAN\n'
69        line1 = translate(_('Admission Letter of'),
70            'waeup.kofa', target_language=portal_language) \
71            + ' %s' % self.context.display_fullname
72        return '%s%s' % (line0, line1)
73
74    @property
75    def _post_text(self):
76        return """You should note the following as conditions for admission:
77
781. At the point of registration, you will be required to present the originals of your
79   certificate(s), Jamb Original Result, a Birth Certificate or a Declaration of
80   Age Certificate and Evidence of Citizenship Certificate.
81
822. Please note that the name by which you are hereby admitted and by which you will
83   be registered is the one which will appear on any certificate that the
84   Federal College of Education, Okene may issue to you on successful completion of
85   your programme except there was a change of name by sworn affidavit or
86   marriage certificate in addition to newspaper publication.
87
883. You are hereby informed that all fees must be paid at the beginning of the
89   academic session. The current school fees can be obtained from the College website.
90
914. You will present at the time of registration the Medical Certificate of Fitness
92   from the Federal College of Education, Okene Medical Centre.
93
945. Students shall be given accommodations on first come, first serve basis.
95
966. The offer is not transferable to another session.
97
987. You will sign a declaration of good conduct except by deferment on your
99   arrival at the College.
100
101Accept my congratulations. Yours faithfully
102
103Ajoge E, A
104Deputy Registrar (Admissions)
105For: Registrar
106"""
107
108    def render(self):
109        students_utils = getUtility(IStudentsUtils)
110        letterhead_path = os.path.join(
111            os.path.dirname(__file__), 'static', 'letterhead_admission.jpg')
112        topMargin=1.8
113        if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP':
114            letterhead_path = None
115            topMargin=1.3
116        return students_utils.renderPDFAdmissionLetter(self,
117            self.context.student, omit_fields=self.omit_fields,
118            letterhead_path=letterhead_path,
119            topMargin=topMargin,
120            post_text=self._post_text)
121
122class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
123    """ Page to view an online payment ticket
124    """
125    grok.context(ICustomStudentOnlinePayment)
126    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
127        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
128    form_fields[
129        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
130    form_fields[
131        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
132
133class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
134    """ Page to add an online payment ticket
135    """
136    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
137        'p_combi')
138
139class OnlinePaymentApproveView(OnlinePaymentApproveView):
140    grok.require('waeup.manageStudent')
141
142class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
143    """Deliver a PDF slip of the context.
144    """
145    grok.context(ICustomStudentOnlinePayment)
146    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
147        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi')
148    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
149    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
150
151class CustomStartClearancePage(StartClearancePage):
152
153    @property
154    def with_ac(self):
155        mode = getattr(self.context, 'current_mode', None)
156        if mode and mode.startswith('ug'):
157            return True
158        return False
159
160class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage):
161    """ Page to display student clearance data
162    """
163
164    @property
165    def form_fields(self):
166        if self.context.is_postgrad:
167            form_fields = grok.AutoFields(
168                ICustomPGStudentClearance).omit('clearance_locked')
169        else:
170            form_fields = grok.AutoFields(
171                ICustomUGStudentClearance).omit('clearance_locked')
172        if not getattr(self.context, 'officer_comment'):
173            form_fields = form_fields.omit('officer_comment')
174        else:
175            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
176        return form_fields
177
178
179class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage):
180    """ Page to edit student clearance data
181    """
182
183    @property
184    def form_fields(self):
185        if self.context.is_postgrad:
186            form_fields = grok.AutoFields(
187                ICustomPGStudentClearance).omit('clr_code')
188        else:
189            form_fields = grok.AutoFields(
190                ICustomUGStudentClearance).omit('clr_code')
191        return form_fields
192
193
194class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
195    """Deliver a PDF slip of the context.
196    """
197
198    @property
199    def form_fields(self):
200        if self.context.is_postgrad:
201            form_fields = grok.AutoFields(
202                ICustomPGStudentClearance).omit('clearance_locked')
203        else:
204            form_fields = grok.AutoFields(
205                ICustomUGStudentClearance).omit('clearance_locked')
206        if not getattr(self.context, 'officer_comment'):
207            form_fields = form_fields.omit('officer_comment')
208        return form_fields
209
210    @property
211    def label(self):
212        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
213
214        line0 = ''
215        if self.context.student.current_mode.startswith('ug'):
216            line0 = 'Directorate of Undergraduate Programme\n'
217        line1 = translate(_('Clearance Slip of'),
218            'waeup.kofa', target_language=portal_language) \
219            + ' %s' % self.context.display_fullname
220        return '%s%s' % (line0, line1)
221
222
223class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
224    """ View to edit student clearance data by student
225    """
226
227    def dataNotComplete(self):
228        return False
229
230    @property
231    def form_fields(self):
232        if self.context.is_postgrad:
233            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
234            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
235            'physical_clearance_date')
236        else:
237            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
238            'clearance_locked', 'clr_code', 'officer_comment',
239            'physical_clearance_date')
240        return form_fields
241
242class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
243    """ Page to add an online payment ticket
244    """
245    buttonname = _('Create bed ticket')
246    notice = ''
247    with_ac = False
248    with_bedselection = True
249
250class CustomExportPDFCourseRegistrationSlip(
251    NigeriaExportPDFCourseRegistrationSlip):
252    """Deliver a PDF slip of the context.
253    """
254    grok.context(ICustomStudentStudyLevel)
255    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
256        'level', 'level_verdict', 'validated_by', 'transcript_remark', 'gpa')
257    form_fields[
258        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
259    omit_fields = ('password', 'suspended', 'suspended_comment',
260        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
261        'flash_notice', 'parents_email', 'entry_session', 'password_updated')
262
263    def render(self):
264        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
265        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
266        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
267        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
268        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
269        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
270        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
271        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
272        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
273        CC = translate(_('Cat.'), target_language=portal_language)
274        studentview = StudentBasePDFFormPage(self.context.student,
275            self.request, self.omit_fields)
276        students_utils = getUtility(IStudentsUtils)
277
278        tabledata = []
279        tableheader = []
280        for i in range(1,7):
281            tabledata.append(sorted(
282                [value for value in self.context.values() if value.semester == i],
283                key=lambda value: str(value.semester) + value.code))
284            tableheader.append([(Code,'code', 2.5),
285                             (Title,'title', 5),
286                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
287                             (Cred, 'credits', 1.5),
288                             (CC, 'course_category', 1.5),
289                             #(Mand, 'mandatory', 1.5),
290                             #(Score, 'score', 1.5),
291                             #(Grade, 'grade', 1.5),
292                             #('Auto', 'automatic', 1.5)
293                             ])
294        return students_utils.renderPDF(
295            self, 'course_registration_slip_%s.pdf' % self.context.student.student_id,
296            self.context.student, studentview,
297            tableheader=tableheader,
298            tabledata=tabledata,
299            omit_fields=self.omit_fields,
300            signatures=self._signatures(),
301            sigs_in_footer=self._sigsInFooter(),
302            )
303
304class ExportPDFExaminationClearanceSlip1(CustomExportPDFCourseRegistrationSlip):
305    """Deliver a PDF slip of the context.
306    """
307    grok.name('examination_clearance_slip_1.pdf')
308    form_fields = None
309    omit_fields = (
310        'password', 'suspended', 'phone', 'date_of_birth',
311        'parents_email', 'current_mode', 'entry_session',
312        'adm_code', 'sex', 'suspended_comment',
313        'flash_notice', 'password_updated', 'current_level')
314    semester = 1
315    tabletitle =  ['', '', '']
316
317    @property
318    def label(self):
319        return '%s First Semester Examination Clearance' % self.context.level_session
320
321    @property
322    def title(self):
323        return ''
324
325    def update(self):
326        if self.context.student.state != VALIDATED \
327            or self.context.student.current_level != self.context.level:
328            self.flash(_('Forbidden'), type="warning")
329            self.redirect(self.url(self.context))
330
331    def render(self):
332        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
333        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
334        studentview = StudentBasePDFFormPage(self.context.student,
335            self.request, self.omit_fields)
336        students_utils = getUtility(IStudentsUtils)
337
338        tabledata = []
339        tableheader = []
340        for i in range(1,7):
341            tabledata.append(sorted(
342                [value for value in self.context.values() if i == self.semester == value.semester],
343                key=lambda value: value.code))
344            tableheader.append([(Code,'code', 2.5),
345                             ('Invigilator\'s Name','inv', 8),
346                             ('Signature and Date','sig', 7),
347                             ])
348        return students_utils.renderPDF(
349            self, 'examination_clearance_slip_%s.pdf' % self.semester,
350            self.context.student, studentview,
351            tableheader=tableheader,
352            tabledata=tabledata,
353            omit_fields=self.omit_fields,
354            topMargin=1.3
355            )
356
357class ExportPDFExaminationClearanceSlip2(ExportPDFExaminationClearanceSlip1):
358    """Deliver a PDF slip of the context.
359    """
360    grok.name('examination_clearance_slip_2.pdf')
361    semester = 2
362
363    @property
364    def label(self):
365        return '%s Second Semester Examination Clearance' % self.context.level_session
366
367class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
368    """ Page to display student study levels
369    """
370    grok.context(ICustomStudentStudyLevel)
371    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level')
372    form_fields[
373        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
374
375class CustomStudyLevelManageFormPage(StudyLevelManageFormPage):
376    """ Page to edit the student study level data
377    """
378
379class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
380    """ Page to edit the student study level data by students
381    """
382
383class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
384    """ Page to display course tickets
385    """
386    form_fields = grok.AutoFields(ICourseTicket).omit(
387        'ticket_session')
388
389class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
390    """ Page to manage course tickets
391    """
392    form_fields = grok.AutoFields(ICourseTicket)
393    form_fields['title'].for_display = True
394    form_fields['fcode'].for_display = True
395    form_fields['dcode'].for_display = True
396    form_fields['semester'].for_display = True
397    form_fields['passmark'].for_display = True
398    form_fields['credits'].for_display = True
399    form_fields['mandatory'].for_display = False
400    form_fields['automatic'].for_display = True
401    form_fields['carry_over'].for_display = True
402    form_fields['ticket_session'].for_display = True
403
404class CustomPaymentsManageFormPage(PaymentsManageFormPage):
405    """ Page to manage the student payments. This manage form page is for
406    both students and students officers. FCEOkene does not allow students
407    to remove any payment ticket.
408    """
409    @property
410    def manage_payments_allowed(self):
411        return checkPermission('waeup.manageStudent', self.context)
412
413class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
414    """ Page to view bed tickets.
415    """
416    with_hostel_selection = True
417
418class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
419    """ Page to manage bed tickets.
420    This manage form page is for both students and students officers.
421    """
422    with_hostel_selection = True
Note: See TracBrowser for help on using the repository browser.