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

Last change on this file since 14641 was 14622, checked in by Henrik Bettermann, 8 years ago

Extend CustomStudentStudyCourseExporter?.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## $Id: export.py 14622 2017-03-13 11:52:24Z 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')
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') \
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              'level', 'code', 'level_session', 'ca', 'score')
118
119class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
120    """
121    """
122    grok.name('levelreportdata')
123
124    fields = ('matric_number', 'display_fullname','level','level_session',
125        'credits_counted', 'credits_passed','level_gpa',
126        'failed_courses','not_taken_courses','cum_credits_taken',
127        'cum_credits_passed','cgpa','remark')
128    title = u'Summary of Result Data'
129
130    def filter_func(self, x, **kw):
131        return get_levels(x)
132
133    def mangle_value(self, value, name, context=None):
134        """The mangler determines the student id, nothing else.
135        """
136        if context is not None:
137            student = context.student
138            format_float = getUtility(IKofaUtils).format_float
139            if name in ('matric_number',
140                        'display_fullname',) and student is not None:
141                value = getattr(student, name, None)
142            elif name == 'credits_counted':
143                value = context.gpa_params[1]
144            elif name == 'credits_passed':
145                value = context.passed_params[2]
146            elif name == 'level_gpa':
147                value = format_float(context.gpa_params[0], 3)
148            elif name == 'failed_courses':
149                value = context.passed_params[4]
150            elif name == 'not_taken_courses':
151                value = context.passed_params[5]
152            elif name == 'cum_credits_taken':
153                value = context.cumulative_params[1]
154            elif name == 'cum_credits_passed':
155                value = context.cumulative_params[4]
156            elif name == 'cgpa':
157                value = format_float(context.cumulative_params[0], 3)
158            elif name == 'remark':
159                value = getattr(context, 'remark', '')
160        return super(
161            LevelReportDataExporter, self).mangle_value(
162            value, name, context=context)
163
Note: See TracBrowser for help on using the repository browser.