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

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

Export level and level_session too.

  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1## $Id: export.py 14595 2017-02-27 08:17:23Z 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))) + ('student_id',)
53
54class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
55    """Exporter for CourseTickets.
56    """
57
58    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
59        ['level', 'code', 'level_session'])) + ('student_id',
60        'certcode', 'display_fullname', 'matric_number')
61
62    def mangle_value(self, value, name, context=None):
63        """The mangler determines the student's id and fullname.
64        """
65        if context is not None:
66            student = context.student
67            if name in ('student_id', 'display_fullname', 'matric_number') \
68                and student is not None:
69                value = getattr(student, name, None)
70        return ExporterBase().mangle_value(value, name, context=context)
71
72class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
73    """Exporter for StudentStudyLevels.
74    """
75    #: Fieldnames considered by this exporter
76    fields = tuple(sorted(iface_names(
77        ICustomStudentStudyLevel))) + (
78        'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa')
79
80    def mangle_value(self, value, name, context=None):
81        """The mangler determines the student id, nothing else.
82        """
83        if name in ('student_id', 'matric_number') and context is not None:
84            student = context.student
85            value = getattr(student, name, None)
86        elif name == 'cgpa':
87            value = context.cumulative_params[0]
88        return super(
89            CustomStudentStudyLevelExporter, self).mangle_value(
90            value, name, context=context)
91
92class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
93    """Exporter for OnlinePayment instances.
94    """
95
96    fields = tuple(
97        sorted(iface_names(
98            ICustomStudentOnlinePayment, exclude_attribs=False,
99            omit=['display_item']))) + (
100            'student_id','state','current_session')
101
102class CustomDataForLecturerExporter(DataForLecturerExporter):
103    """
104    """
105
106    fields = ('matric_number', 'student_id','display_fullname',
107              'level', 'code', 'level_session', 'ca', 'score')
108
109class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase):
110    """
111    """
112    grok.name('levelreportdata')
113
114    fields = ('matric_number', 'display_fullname','level','level_session',
115        'credits_counted', 'credits_passed','level_gpa',
116        'failed_courses','not_taken_courses','cum_credits_taken',
117        'cum_credits_passed','cgpa','remark')
118    title = u'Summary of Result Data'
119
120    def filter_func(self, x, **kw):
121        return get_levels(x)
122
123    def mangle_value(self, value, name, context=None):
124        """The mangler determines the student id, nothing else.
125        """
126        if context is not None:
127            student = context.student
128            format_float = getUtility(IKofaUtils).format_float
129            if name in ('matric_number',
130                        'display_fullname',) and student is not None:
131                value = getattr(student, name, None)
132            elif name == 'credits_counted':
133                value = context.gpa_params[1]
134            elif name == 'credits_passed':
135                value = context.passed_params[2]
136            elif name == 'level_gpa':
137                value = format_float(context.gpa_params[0], 3)
138            elif name == 'failed_courses':
139                value = context.passed_params[4]
140            elif name == 'not_taken_courses':
141                value = context.passed_params[5]
142            elif name == 'cum_credits_taken':
143                value = context.cumulative_params[1]
144            elif name == 'cum_credits_passed':
145                value = context.cumulative_params[4]
146            elif name == 'cgpa':
147                value = format_float(context.cumulative_params[0], 3)
148            elif name == 'remark':
149                value = getattr(context, 'remark', '')
150        return super(
151            LevelReportDataExporter, self).mangle_value(
152            value, name, context=context)
153
Note: See TracBrowser for help on using the repository browser.