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

Last change on this file since 10222 was 10102, checked in by Henrik Bettermann, 12 years ago

Changes requested in ticket #59.

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