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

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

Customize course registration slip.

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1## $Id: browser.py 10692 2013-11-04 10:57:34Z 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.component import getUtility
21from hurry.workflow.interfaces import IWorkflowInfo
22from waeup.kofa.interfaces import ADMITTED, IKofaUtils
23from waeup.kofa.browser.layout import UtilityView
24from waeup.kofa.students.interfaces import IStudentsUtils
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
26from waeup.kofa.students.browser import (
27    StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage,
28    StudentBasePDFFormPage)
29from waeup.kwarapoly.students.interfaces import (
30    ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel)
31from waeup.kwarapoly.interfaces import MessageFactory as _
32from waeup.kofa.students.workflow import (
33    ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED,
34    VALIDATED, GRADUATED, TRANSCRIPT, CREATED, CLEARANCE)
35from kofacustom.nigeria.students.browser import (
36    NigeriaOnlinePaymentDisplayFormPage,
37    NigeriaOnlinePaymentAddFormPage,
38    NigeriaExportPDFPaymentSlipPage,
39    NigeriaStudentClearanceEditFormPage,
40    NigeriaExportPDFCourseRegistrationSlipPage,
41    )
42
43from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
44
45class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
46    """ Page to view an online payment ticket
47    """
48    grok.context(ICustomStudentOnlinePayment)
49    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
50        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
51    form_fields[
52        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
53    form_fields[
54        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
55
56class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
57    """ Page to add an online payment ticket
58    """
59    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
60        'p_category')
61
62class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
63    """Deliver a PDF slip of the context.
64    """
65    grok.context(ICustomStudentOnlinePayment)
66    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
67        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
68    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
69    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
70
71class CustomStartClearancePage(StartClearancePage):
72
73    with_ac = False
74
75class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
76    """ View to edit student clearance data by student
77    """
78
79    def dataNotComplete(self):
80        return False
81
82class BedTicketAddPage(BedTicketAddPage):
83    """ Page to add an online payment ticket
84    """
85    buttonname = _('Create bed ticket')
86    notice = ''
87    with_ac = False
88
89class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
90    """Deliver a PDF Admission slip.
91    """
92    grok.context(ICustomStudent)
93
94    omit_fields = ('date_of_birth',)
95
96    form_fields = grok.AutoFields(ICustomStudent).select('student_id', 'reg_number')
97
98    def render(self):
99        if self.context.state in (CREATED, ADMITTED,
100                                  CLEARANCE, REQUESTED, CLEARED):
101            self.flash('Not allowed.')
102            self.redirect(self.url(self.context))
103            return
104        students_utils = getUtility(IStudentsUtils)
105        return students_utils.renderPDFAdmissionLetter(self,
106            self.context.student, omit_fields=self.omit_fields)
107
108class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
109    """Deliver a PDF Admission nostification slip.
110    """
111    grok.context(ICustomStudent)
112    grok.name('admission_notification.pdf')
113    grok.require('waeup.viewStudent')
114    prefix = 'form'
115    label = 'Notification of Provisional Admission'
116
117    omit_fields = ('date_of_birth',)
118
119    form_fields = grok.AutoFields(ICustomStudent).select(
120        'student_id', 'reg_number', 'sex', 'lga')
121
122    def render(self):
123        if self.context.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
124            self.flash('Not allowed.')
125            self.redirect(self.url(self.context))
126            return
127        students_utils = getUtility(IStudentsUtils)
128        pre_text = ''
129        post_text = '<strong>Instructions for Freshers</strong>'
130        return students_utils.renderPDFAdmissionLetter(self,
131            self.context.student, omit_fields=self.omit_fields,
132            pre_text=pre_text, post_text=post_text)
133
134# copied from waeup.aaue
135class CustomExportPDFCourseRegistrationSlipPage(
136    NigeriaExportPDFCourseRegistrationSlipPage):
137    """Deliver a PDF slip of the context.
138    """
139    grok.context(ICustomStudentStudyLevel)
140    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
141        'level_session', 'level_verdict',
142        'validated_by', 'validation_date', 'gpa')
143
144    omit_fields = ('password', 'suspended', 'suspended_comment',
145        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
146        'department', 'current_mode')
147
148    @property
149    def title(self):
150        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
151        return translate(_('Credits Registered'), 'waeup.kofa',
152            target_language=portal_language)
153
154    def _signatures(self):
155        return (
156            [('I have selected the course on the advise of my Head of '
157             'Department. <br>', _('Student\'s Signature'), '<br>')],
158            [('This student has satisfied the department\'s requirements. '
159             'I recommend to approve the course registration. <br>',
160             _('Head of Department\'s Signature'), '<br>')],
161            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
162            [('', _('Director\'s Signature'))]
163            )
164
165    def render(self):
166        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
167        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
168        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
169        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
170        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
171        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
172        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
173        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
174            target_language=portal_language)
175        studentview = StudentBasePDFFormPage(self.context.student,
176            self.request, self.omit_fields)
177        students_utils = getUtility(IStudentsUtils)
178
179        tabledata = []
180        tableheader = []
181        contenttitle = []
182        for i in range(1,7):
183            tabledata.append(sorted(
184                [value for value in self.context.values() if value.semester == i],
185                key=lambda value: str(value.semester) + value.code))
186            tableheader.append([(Code,'code', 2.0),
187                               (Title,'title', 7),
188                               (Cred, 'credits', 1.5),
189                               (Score, 'score', 1.4),
190                               (Grade, 'grade', 1.4),
191                               (Signature, 'dummy', 3),
192                               ])
193        if len(self.label.split('\n')) == 3:
194            topMargin = 1.9
195        elif len(self.label.split('\n')) == 2:
196            topMargin = 1.7
197        else:
198            topMargin = 1.5
199        return students_utils.renderPDF(
200            self, 'course_registration_slip.pdf',
201            self.context.student, studentview,
202            tableheader=tableheader,
203            tabledata=tabledata,
204            signatures=self._signatures(),
205            topMargin=topMargin,
206            omit_fields=self.omit_fields
207            )
Note: See TracBrowser for help on using the repository browser.