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

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

Adjust to base package.

Increase title column width.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: browser.py 10269 2013-06-01 06:28:59Z 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('total_credits')
71    form_fields[
72        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
73
74class CustomExportPDFCourseRegistrationSlipPage(
75    NigeriaExportPDFCourseRegistrationSlipPage):
76    """Deliver a PDF slip of the context.
77    """
78    grok.context(ICustomStudentStudyLevel)
79    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
80        'level_session', 'level_verdict',
81        'validated_by', 'validation_date', 'gpa')
82
83    omit_fields = ('password', 'suspended', 'suspended_comment',
84        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'department')
85
86    @property
87    def label(self):
88        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
89        lang = self.request.cookies.get('kofa.language', portal_language)
90        level_title = translate(self.context.level_title, 'waeup.kofa',
91            target_language=lang)
92        line0 = ''
93        if self.context.student.current_mode.endswith('_pt'):
94            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
95        line1 = translate(_('Course Registration Slip'),
96            'waeup.kofa', target_language=portal_language) \
97            + ' %s' % level_title
98        line2 = translate(_('Session'),
99            'waeup.kofa', target_language=portal_language) \
100            + ' %s' % self.context.getSessionString
101        return '%s%s\n%s' % (line0, line1, line2)
102
103    @property
104    def title(self):
105        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
106        return translate(_('Units Registered'), 'waeup.kofa',
107            target_language=portal_language)
108
109    def _signatures(self):
110        return (
111            [('I have selected the course on the advise of my Head of '
112             'Department. <br>', _('Student\'s Signature'), '<br>')],
113            [('This student has satisfied the department\'s requirements. '
114             'I recommend to approve the course registration. <br>',
115             _('Head of Department\'s Signature'), '<br>')],
116            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
117            [('', _('Director\'s Signature'))]
118            )
119
120    def render(self):
121        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
122        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
123        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
124        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
125        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
126        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
127        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
128        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
129            target_language=portal_language)
130        studentview = StudentBasePDFFormPage(self.context.student,
131            self.request, self.omit_fields)
132        students_utils = getUtility(IStudentsUtils)
133        tabledata_1 = sorted(
134            [value for value in self.context.values() if value.semester == 1],
135            key=lambda value: str(value.semester) + value.code)
136        tabledata_2 = sorted(
137            [value for value in self.context.values() if value.semester == 2],
138            key=lambda value: str(value.semester) + value.code)
139        tableheader = [(Code,'code', 2.0),
140                         (Title,'title', 7),
141                         (Cred, 'credits', 1.5),
142                         (Score, 'score', 1.4),
143                         (Grade, 'grade', 1.4),
144                         (Signature, 'dummy', 3),
145                         ]
146        if len(self.label.split('\n')) == 3:
147            topMargin = 1.9
148        elif len(self.label.split('\n')) == 2:
149            topMargin = 1.7
150        else:
151            topMargin = 1.5
152        return students_utils.renderPDF(
153            self, 'course_registration_slip.pdf',
154            self.context.student, studentview,
155            tableheader_1=tableheader,
156            tabledata_1=tabledata_1,
157            tableheader_2=tableheader,
158            tabledata_2=tabledata_2,
159            signatures=self._signatures(),
160            topMargin=topMargin,
161            omit_fields=self.omit_fields
162            )
Note: See TracBrowser for help on using the repository browser.