source: main/waeup.aaue/trunk/src/waeup/aaue/students/export.py @ 15735

Last change on this file since 15735 was 15471, checked in by Henrik Bettermann, 6 years ago

Store xml split data in payment ticket.

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1## $Id: export.py 15471 2019-06-21 08:28:09Z henrik $
2##
3## Copyright (C) 2011 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##
18"""Exporters for student related stuff.
19"""
20import grok
21from zope.component import getUtility
22from waeup.kofa.utils.batching import ExporterBase
23from waeup.kofa.utils.helpers import iface_names
24from waeup.kofa.interfaces import IKofaUtils
25from waeup.kofa.students.export import (get_levels,
26    DataForLecturerExporter, StudentExporterBase,
27    SchoolFeePaymentsOverviewExporter, StudentExporter)
28from waeup.aaue.students.interfaces import (
29    ICustomStudent, ICustomStudentStudyCourse,
30    ICustomStudentStudyLevel,
31    ICustomCourseTicket,
32    ICustomStudentOnlinePayment)
33from kofacustom.nigeria.students.export import (
34    NigeriaStudentExporter, NigeriaStudentStudyCourseExporter,
35    NigeriaStudentStudyLevelExporter,
36    NigeriaCourseTicketExporter, NigeriaStudentPaymentExporter)
37
38
39class CustomStudentExporter(NigeriaStudentExporter):
40    """Exporter for Students.
41    """
42
43    fields = tuple(sorted(iface_names(
44        ICustomStudent, omit=['loggerInfo']))) + (
45        'password', 'state', 'history', 'certcode', 'is_postgrad',
46        'current_level', 'current_session')
47
48class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
49    """Exporter for StudentStudyCourses.
50    """
51
52    fields = tuple(
53        sorted(iface_names(ICustomStudentStudyCourse))) + (
54            'matric_number', 'state', 'student_id',)
55
56    def mangle_value(self, value, name, context=None):
57        if name == 'certificate' and value is not None:
58            # XXX: hopefully cert codes are unique site-wide
59            value = value.code
60        if name in ('student_id', 'matric_number', 'state') and context is not None:
61            student = context.student
62            value = getattr(student, name, None)
63        return ExporterBase().mangle_value(value, name, context=context)
64
65class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
66    """Exporter for CourseTickets.
67    """
68
69    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
70        ['level', 'code', 'level_session'])) + ('student_id',
71        'certcode', 'display_fullname', 'matric_number', 'state')
72
73    def mangle_value(self, value, name, context=None):
74        """The mangler determines the student's id and fullname.
75        """
76        if context is not None:
77            student = context.student
78            if name in ('student_id', 'display_fullname', 'matric_number', 'state') \
79                and student is not None:
80                value = getattr(student, name, None)
81        return ExporterBase().mangle_value(value, name, context=context)
82
83class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
84    """Exporter for StudentStudyLevels.
85    """
86    #: Fieldnames considered by this exporter
87    fields = tuple(sorted(iface_names(
88        ICustomStudentStudyLevel))) + (
89        'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa')
90
91    def mangle_value(self, value, name, context=None):
92        """The mangler determines the student id, nothing else.
93        """
94        if name in ('student_id', 'matric_number') and context is not None:
95            student = context.student
96            value = getattr(student, name, None)
97        elif name == 'cgpa':
98            value = context.cumulative_params[0]
99        return super(
100            CustomStudentStudyLevelExporter, self).mangle_value(
101            value, name, context=context)
102
103class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
104    """Exporter for OnlinePayment instances.
105    """
106
107    fields = tuple(
108        sorted(iface_names(
109            ICustomStudentOnlinePayment, exclude_attribs=False,
110            omit=['display_item','formatted_p_date']))) + (
111            'student_id','state','current_session')
112
113class CustomDataForLecturerExporter(DataForLecturerExporter):
114    """
115    """
116
117    fields = ('matric_number', 'student_id','display_fullname',
118              'depcode', 'faccode',
119              'level', 'code', 'level_session', 'ca', 'score',
120              'total_score', 'grade', 'imported_ts')
121
122    def mangle_value(self, value, name, context=None):
123        """The mangler determines the student's id and fullname.
124        """
125        if context is not None:
126            student = context.student
127            if name in ('matric_number',
128                        'reg_number',
129                        'student_id',
130                        'display_fullname',
131                        'depcode',
132                        'faccode') and student is not None:
133                value = getattr(student, name, None)
134        return super(
135            DataForLecturerExporter, self).mangle_value(
136            value, name, context=context)
137
138class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
139    """
140    """
141    grok.name('levelreportdata')
142
143    fields = ('matric_number', 'display_fullname','level','level_session',
144        'credits_counted', 'credits_passed','level_gpa',
145        'failed_courses','not_taken_courses','cum_credits_taken',
146        'cum_credits_passed','cgpa','remark')
147    title = u'Summary of Result Data'
148
149    def filter_func(self, x, **kw):
150        return get_levels(x)
151
152    def mangle_value(self, value, name, context=None):
153        """The mangler determines the student id, nothing else.
154        """
155        if context is not None:
156            student = context.student
157            format_float = getUtility(IKofaUtils).format_float
158            if name in ('matric_number',
159                        'display_fullname',) and student is not None:
160                value = getattr(student, name, None)
161            elif name == 'credits_counted':
162                value = context.gpa_params[1]
163            elif name == 'credits_passed':
164                value = context.passed_params[2]
165            elif name == 'level_gpa':
166                value = format_float(context.gpa_params[0], 3)
167            elif name == 'failed_courses':
168                value = context.passed_params[4]
169            elif name == 'not_taken_courses':
170                value = context.passed_params[5]
171            elif name == 'cum_credits_taken':
172                value = context.cumulative_params[1]
173            elif name == 'cum_credits_passed':
174                value = context.cumulative_params[4]
175            elif name == 'cgpa':
176                value = format_float(context.cumulative_params[0], 3)
177            elif name == 'remark':
178                value = getattr(context, 'remark', '')
179        return super(
180            LevelReportDataExporter, self).mangle_value(
181            value, name, context=context)
182
183class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter):
184    """
185    """
186
187    def mangle_value(self, value, name, context=None):
188        """
189        """
190        if name in self.year_range_tuple and context is not None:
191            value = 0
192            for ticket in context['payments'].values():
193                if ticket.p_category in (
194                    'schoolfee',
195                    'schoolfee_1',
196                    'schoolfee_2',
197                    'schoolfee_incl',) and \
198                    ticket.p_session == int(name):
199                    if ticket.p_state == 'waived':
200                        value = 'waived'
201                        break
202                    if ticket.p_state == 'paid':
203                        try:
204                            value += ticket.amount_auth
205                        except TypeError:
206                            pass
207            if value == 0:
208                value = ''
209            elif isinstance(value, float):
210                value = round(value, 2)
211        return super(
212            StudentExporter, self).mangle_value(
213            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.