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

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

Add state column.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: export.py 15336 2019-02-28 06:46:07Z 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,)
27from waeup.aaue.students.interfaces import (
28    ICustomStudent, ICustomStudentStudyCourse,
29    ICustomStudentStudyLevel,
30    ICustomCourseTicket,
31    ICustomStudentOnlinePayment)
32from kofacustom.nigeria.students.export import (
33    NigeriaStudentExporter, NigeriaStudentStudyCourseExporter,
34    NigeriaStudentStudyLevelExporter,
35    NigeriaCourseTicketExporter, NigeriaStudentPaymentExporter)
36
37
38class CustomStudentExporter(NigeriaStudentExporter):
39    """Exporter for Students.
40    """
41
42    fields = tuple(sorted(iface_names(
43        ICustomStudent, omit=['loggerInfo']))) + (
44        'password', 'state', 'history', 'certcode', 'is_postgrad',
45        'current_level', 'current_session')
46
47class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
48    """Exporter for StudentStudyCourses.
49    """
50
51    fields = tuple(
52        sorted(iface_names(ICustomStudentStudyCourse))) + (
53            'matric_number', 'state', 'student_id',)
54
55    def mangle_value(self, value, name, context=None):
56        if name == 'certificate' and value is not None:
57            # XXX: hopefully cert codes are unique site-wide
58            value = value.code
59        if name in ('student_id', 'matric_number', 'state') and context is not None:
60            student = context.student
61            value = getattr(student, name, None)
62        return ExporterBase().mangle_value(value, name, context=context)
63
64class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
65    """Exporter for CourseTickets.
66    """
67
68    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
69        ['level', 'code', 'level_session'])) + ('student_id',
70        'certcode', 'display_fullname', 'matric_number', 'state')
71
72    def mangle_value(self, value, name, context=None):
73        """The mangler determines the student's id and fullname.
74        """
75        if context is not None:
76            student = context.student
77            if name in ('student_id', 'display_fullname', 'matric_number', 'state') \
78                and student is not None:
79                value = getattr(student, name, None)
80        return ExporterBase().mangle_value(value, name, context=context)
81
82class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
83    """Exporter for StudentStudyLevels.
84    """
85    #: Fieldnames considered by this exporter
86    fields = tuple(sorted(iface_names(
87        ICustomStudentStudyLevel))) + (
88        'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa')
89
90    def mangle_value(self, value, name, context=None):
91        """The mangler determines the student id, nothing else.
92        """
93        if name in ('student_id', 'matric_number') and context is not None:
94            student = context.student
95            value = getattr(student, name, None)
96        elif name == 'cgpa':
97            value = context.cumulative_params[0]
98        return super(
99            CustomStudentStudyLevelExporter, self).mangle_value(
100            value, name, context=context)
101
102class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
103    """Exporter for OnlinePayment instances.
104    """
105
106    fields = tuple(
107        sorted(iface_names(
108            ICustomStudentOnlinePayment, exclude_attribs=False,
109            omit=['display_item']))) + (
110            'student_id','state','current_session')
111
112class CustomDataForLecturerExporter(DataForLecturerExporter):
113    """
114    """
115
116    fields = ('matric_number', 'student_id','display_fullname',
117              'depcode', 'faccode',
118              'level', 'code', 'level_session', 'ca', 'score',
119              'total_score', 'grade')
120
121    def mangle_value(self, value, name, context=None):
122        """The mangler determines the student's id and fullname.
123        """
124        if context is not None:
125            student = context.student
126            if name in ('matric_number',
127                        'reg_number',
128                        'student_id',
129                        'display_fullname',
130                        'depcode',
131                        'faccode') and student is not None:
132                value = getattr(student, name, None)
133        return super(
134            DataForLecturerExporter, self).mangle_value(
135            value, name, context=context)
136
137class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
138    """
139    """
140    grok.name('levelreportdata')
141
142    fields = ('matric_number', 'display_fullname','level','level_session',
143        'credits_counted', 'credits_passed','level_gpa',
144        'failed_courses','not_taken_courses','cum_credits_taken',
145        'cum_credits_passed','cgpa','remark')
146    title = u'Summary of Result Data'
147
148    def filter_func(self, x, **kw):
149        return get_levels(x)
150
151    def mangle_value(self, value, name, context=None):
152        """The mangler determines the student id, nothing else.
153        """
154        if context is not None:
155            student = context.student
156            format_float = getUtility(IKofaUtils).format_float
157            if name in ('matric_number',
158                        'display_fullname',) and student is not None:
159                value = getattr(student, name, None)
160            elif name == 'credits_counted':
161                value = context.gpa_params[1]
162            elif name == 'credits_passed':
163                value = context.passed_params[2]
164            elif name == 'level_gpa':
165                value = format_float(context.gpa_params[0], 3)
166            elif name == 'failed_courses':
167                value = context.passed_params[4]
168            elif name == 'not_taken_courses':
169                value = context.passed_params[5]
170            elif name == 'cum_credits_taken':
171                value = context.cumulative_params[1]
172            elif name == 'cum_credits_passed':
173                value = context.cumulative_params[4]
174            elif name == 'cgpa':
175                value = format_float(context.cumulative_params[0], 3)
176            elif name == 'remark':
177                value = getattr(context, 'remark', '')
178        return super(
179            LevelReportDataExporter, self).mangle_value(
180            value, name, context=context)
181
Note: See TracBrowser for help on using the repository browser.