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

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

Omit current_mode.

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