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

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

Add log message.

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