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

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

Store xml split data in payment ticket.

  • Property svn:keywords set to Id
File size: 8.3 KB
RevLine 
[11546]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"""
[14593]20import grok
21from zope.component import getUtility
[13569]22from waeup.kofa.utils.batching import ExporterBase
[13768]23from waeup.kofa.utils.helpers import iface_names
[14593]24from waeup.kofa.interfaces import IKofaUtils
25from waeup.kofa.students.export import (get_levels,
[15452]26    DataForLecturerExporter, StudentExporterBase,
27    SchoolFeePaymentsOverviewExporter, StudentExporter)
[11546]28from waeup.aaue.students.interfaces import (
29    ICustomStudent, ICustomStudentStudyCourse,
30    ICustomStudentStudyLevel,
31    ICustomCourseTicket,
32    ICustomStudentOnlinePayment)
33from kofacustom.nigeria.students.export import (
[12081]34    NigeriaStudentExporter, NigeriaStudentStudyCourseExporter,
[11546]35    NigeriaStudentStudyLevelExporter,
[12876]36    NigeriaCourseTicketExporter, NigeriaStudentPaymentExporter)
[11546]37
[13768]38
[12081]39class CustomStudentExporter(NigeriaStudentExporter):
[11546]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(
[14622]53        sorted(iface_names(ICustomStudentStudyCourse))) + (
54            'matric_number', 'state', 'student_id',)
[11546]55
[14622]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
[11546]65class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
66    """Exporter for CourseTickets.
67    """
68
69    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
70        ['level', 'code', 'level_session'])) + ('student_id',
[15336]71        'certcode', 'display_fullname', 'matric_number', 'state')
[11546]72
[13569]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
[15336]78            if name in ('student_id', 'display_fullname', 'matric_number', 'state') \
[13569]79                and student is not None:
80                value = getattr(student, name, None)
81        return ExporterBase().mangle_value(value, name, context=context)
82
[11546]83class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
84    """Exporter for StudentStudyLevels.
85    """
86    #: Fieldnames considered by this exporter
87    fields = tuple(sorted(iface_names(
[12876]88        ICustomStudentStudyLevel))) + (
[14442]89        'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa')
[11546]90
[14436]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)
[14442]97        elif name == 'cgpa':
98            value = context.cumulative_params[0]
[14436]99        return super(
100            CustomStudentStudyLevelExporter, self).mangle_value(
101            value, name, context=context)
102
[12876]103class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
[11546]104    """Exporter for OnlinePayment instances.
105    """
106
107    fields = tuple(
108        sorted(iface_names(
109            ICustomStudentOnlinePayment, exclude_attribs=False,
[15471]110            omit=['display_item','formatted_p_date']))) + (
[11546]111            'student_id','state','current_session')
112
[13768]113class CustomDataForLecturerExporter(DataForLecturerExporter):
114    """
115    """
116
[14360]117    fields = ('matric_number', 'student_id','display_fullname',
[14701]118              'depcode', 'faccode',
119              'level', 'code', 'level_session', 'ca', 'score',
[15414]120              'total_score', 'grade', 'imported_ts')
[13768]121
[14701]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
[14593]138class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
139    """
140    """
141    grok.name('levelreportdata')
142
[14595]143    fields = ('matric_number', 'display_fullname','level','level_session',
[14593]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
[15452]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.