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

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

Uups, re-add fields.

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1## $Id: export.py 16039 2020-03-13 12:24:01Z 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', 'grade',
72        'total_score')
73
74    def mangle_value(self, value, name, context=None):
75        """The mangler determines the student's id and fullname.
76        """
77        if context is not None:
78            student = context.student
79            if name in ('student_id', 'display_fullname', 'matric_number', 'state') \
80                and student is not None:
81                value = getattr(student, name, None)
82        return ExporterBase().mangle_value(value, name, context=context)
83
84class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
85    """Exporter for StudentStudyLevels.
86    """
87    #: Fieldnames considered by this exporter
88    fields = tuple(sorted(iface_names(
89        ICustomStudentStudyLevel))) + (
90        'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa')
91
92    def mangle_value(self, value, name, context=None):
93        """The mangler determines the student id, nothing else.
94        """
95        if name in ('student_id', 'matric_number') and context is not None:
96            student = context.student
97            value = getattr(student, name, None)
98        elif name == 'cgpa':
99            value = context.cumulative_params[0]
100        return super(
101            CustomStudentStudyLevelExporter, self).mangle_value(
102            value, name, context=context)
103
104class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
105    """Exporter for OnlinePayment instances.
106    """
107
108    fields = tuple(
109        sorted(iface_names(
110            ICustomStudentOnlinePayment, exclude_attribs=False,
111            omit=['display_item','formatted_p_date']))) + (
112            'student_id','state','current_session')
113
114class CustomDataForLecturerExporter(DataForLecturerExporter):
115    """
116    """
117
118    fields = ('matric_number', 'student_id','display_fullname',
119              'depcode', 'faccode',
120              'level', 'code', 'level_session', 'ca', 'score',
121              'total_score', 'grade', 'imported_ts')
122
123    def mangle_value(self, value, name, context=None):
124        """The mangler determines the student's id and fullname.
125        """
126        if context is not None:
127            student = context.student
128            if name in ('matric_number',
129                        'reg_number',
130                        'student_id',
131                        'display_fullname',
132                        'depcode',
133                        'faccode') and student is not None:
134                value = getattr(student, name, None)
135        return super(
136            DataForLecturerExporter, self).mangle_value(
137            value, name, context=context)
138
139class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
140    """
141    """
142    grok.name('levelreportdata')
143
144    fields = ('matric_number', 'display_fullname','level','level_session',
145        'credits_counted', 'credits_passed','level_gpa',
146        'failed_courses','not_taken_courses','cum_credits_taken',
147        'cum_credits_passed','cgpa','remark')
148    title = u'Summary of Result Data'
149
150    def filter_func(self, x, **kw):
151        return get_levels(x, **kw)
152
153    def mangle_value(self, value, name, context=None):
154        """The mangler determines the student id, nothing else.
155        """
156        if context is not None:
157            student = context.student
158            format_float = getUtility(IKofaUtils).format_float
159            if name in ('matric_number',
160                        'display_fullname',) and student is not None:
161                value = getattr(student, name, None)
162            elif name == 'credits_counted':
163                value = context.gpa_params[1]
164            elif name == 'credits_passed':
165                value = context.passed_params[2]
166            elif name == 'level_gpa':
167                value = format_float(context.gpa_params[0], 3)
168            elif name == 'failed_courses':
169                value = context.passed_params[4]
170            elif name == 'not_taken_courses':
171                value = context.passed_params[5]
172            elif name == 'cum_credits_taken':
173                value = context.cumulative_params[1]
174            elif name == 'cum_credits_passed':
175                value = context.cumulative_params[4]
176            elif name == 'cgpa':
177                value = format_float(context.cumulative_params[0], 3)
178            elif name == 'remark':
179                value = getattr(context, 'remark', '')
180        return super(
181            LevelReportDataExporter, self).mangle_value(
182            value, name, context=context)
183
184class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter):
185    """
186    """
187
188    def mangle_value(self, value, name, context=None):
189        """
190        """
191        if name in self.year_range_tuple and context is not None:
192            value = 0
193            for ticket in context['payments'].values():
194                if ticket.p_category in (
195                    'schoolfee',
196                    'schoolfee_1',
197                    'schoolfee_2',
198                    'schoolfee_incl',) and \
199                    ticket.p_session == int(name):
200                    if ticket.p_state == 'waived':
201                        value = 'waived'
202                        break
203                    if ticket.p_state == 'paid':
204                        try:
205                            value += ticket.amount_auth
206                        except TypeError:
207                            pass
208            if value == 0:
209                value = ''
210            elif isinstance(value, float):
211                value = round(value, 2)
212        return super(
213            StudentExporter, self).mangle_value(
214            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.