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

Last change on this file since 16814 was 16617, checked in by Henrik Bettermann, 3 years ago

Export total_credits, see #672.

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