source: main/waeup.aaue/trunk/src/waeup/aaue/students/browser.py @ 10480

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

Reinvent unrectified sessional gpa (adjustments to base package).

  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1## $Id: browser.py 10480 2013-08-12 09:08:35Z 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 waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
22from waeup.kofa.interfaces import IKofaUtils
23from waeup.kofa.students.interfaces import IStudentsUtils
24from waeup.kofa.students.browser import (
25    StudentBasePDFFormPage,
26    CourseTicketAddFormPage,
27    StudyLevelDisplayFormPage,
28    )
29from kofacustom.nigeria.students.browser import (
30    NigeriaOnlinePaymentDisplayFormPage,
31    NigeriaOnlinePaymentAddFormPage,
32    NigeriaExportPDFPaymentSlipPage,
33    NigeriaExportPDFCourseRegistrationSlipPage
34    )
35from waeup.aaue.students.interfaces import (
36    ICustomStudentOnlinePayment,
37    ICustomStudentStudyLevel)
38from waeup.aaue.interfaces import MessageFactory as _
39
40class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
41    """ Page to view an online payment ticket
42    """
43    grok.context(ICustomStudentOnlinePayment)
44    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
45        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
46    form_fields[
47        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
48    form_fields[
49        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
50
51class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
52    """ Page to add an online payment ticket
53    """
54    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
55        'p_category')
56
57class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
58    """Deliver a PDF slip of the context.
59    """
60    grok.context(ICustomStudentOnlinePayment)
61    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
62        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
63    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
64    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
65
66class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
67    """ Page to display student study levels
68    """
69    grok.context(ICustomStudentStudyLevel)
70    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
71        'total_credits', 'gpa')
72    form_fields[
73        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
74
75class CustomExportPDFCourseRegistrationSlipPage(
76    NigeriaExportPDFCourseRegistrationSlipPage):
77    """Deliver a PDF slip of the context.
78    """
79    grok.context(ICustomStudentStudyLevel)
80    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
81        'level_session', 'level_verdict',
82        'validated_by', 'validation_date', 'gpa')
83
84    omit_fields = ('password', 'suspended', 'suspended_comment',
85        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'department')
86
87    @property
88    def label(self):
89        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
90        lang = self.request.cookies.get('kofa.language', portal_language)
91        level_title = translate(self.context.level_title, 'waeup.kofa',
92            target_language=lang)
93        line0 = ''
94        if self.context.student.current_mode.endswith('_pt'):
95            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
96        line1 = translate(_('Course Registration Slip'),
97            'waeup.kofa', target_language=portal_language) \
98            + ' %s' % level_title
99        line2 = translate(_('Session'),
100            'waeup.kofa', target_language=portal_language) \
101            + ' %s' % self.context.getSessionString
102        return '%s%s\n%s' % (line0, line1, line2)
103
104    @property
105    def title(self):
106        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
107        return translate(_('Units Registered'), 'waeup.kofa',
108            target_language=portal_language)
109
110    def _signatures(self):
111        return (
112            [('I have selected the course on the advise of my Head of '
113             'Department. <br>', _('Student\'s Signature'), '<br>')],
114            [('This student has satisfied the department\'s requirements. '
115             'I recommend to approve the course registration. <br>',
116             _('Head of Department\'s Signature'), '<br>')],
117            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
118            [('', _('Director\'s Signature'))]
119            )
120
121    def render(self):
122        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
123        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
124        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
125        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
126        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
127        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
128        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
129        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
130            target_language=portal_language)
131        studentview = StudentBasePDFFormPage(self.context.student,
132            self.request, self.omit_fields)
133        students_utils = getUtility(IStudentsUtils)
134
135        tabledata = []
136        tableheader = []
137        contenttitle = []
138        for i in range(1,7):
139            tabledata.append(sorted(
140                [value for value in self.context.values() if value.semester == i],
141                key=lambda value: str(value.semester) + value.code))
142            tableheader.append([(Code,'code', 2.0),
143                               (Title,'title', 7),
144                               (Cred, 'credits', 1.5),
145                               (Score, 'score', 1.4),
146                               (Grade, 'grade', 1.4),
147                               (Signature, 'dummy', 3),
148                               ])
149        if len(self.label.split('\n')) == 3:
150            topMargin = 1.9
151        elif len(self.label.split('\n')) == 2:
152            topMargin = 1.7
153        else:
154            topMargin = 1.5
155        return students_utils.renderPDF(
156            self, 'course_registration_slip.pdf',
157            self.context.student, studentview,
158            tableheader=tableheader,
159            tabledata=tabledata,
160            signatures=self._signatures(),
161            topMargin=topMargin,
162            omit_fields=self.omit_fields
163            )
Note: See TracBrowser for help on using the repository browser.