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

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

Adjust to changes made in base package.

  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1## $Id: browser.py 9990 2013-02-24 17:45:04Z 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        'total_credits', '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        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
121        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
122        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
123        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
124        Signature = translate(_('Course Lecturer\'s Signature'), 'waeup.aaue',
125            target_language=portal_language)
126        studentview = StudentBasePDFFormPage(self.context.student,
127            self.request, self.omit_fields)
128        students_utils = getUtility(IStudentsUtils)
129        tabledata_1 = sorted(
130            [value for value in self.context.values() if value.semester == 1],
131            key=lambda value: str(value.semester) + value.code)
132        tabledata_2 = sorted(
133            [value for value in self.context.values() if value.semester == 2],
134            key=lambda value: str(value.semester) + value.code)
135        tableheader = [(Code,'code', 2.0),
136                         (Title,'title', 5),
137                         (Dept,'dcode', 1.5), #(Faculty,'fcode', 1.5),
138                         (Cred, 'credits', 1.5),
139                         (Score, 'score', 1.4),
140                         (Grade, 'grade', 1.4),
141                         (Signature, 'dummy', 3),
142                         ]
143        if len(self.label.split('\n')) == 3:
144            topMargin = 1.9
145        elif len(self.label.split('\n')) == 2:
146            topMargin = 1.7
147        else:
148            topMargin = 1.5
149        return students_utils.renderPDF(
150            self, 'course_registration_slip.pdf',
151            self.context.student, studentview,
152            tableheader_1=tableheader,
153            tabledata_1=tabledata_1,
154            tableheader_2=tableheader,
155            tabledata_2=tabledata_2,
156            signatures=self._signatures(),
157            topMargin=topMargin
158            )
Note: See TracBrowser for help on using the repository browser.