source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/export.py @ 18068

Last change on this file since 18068 was 18068, checked in by Henrik Bettermann, 10 hours ago

Add fields to exporter.

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1## $Id: export.py 18068 2025-05-04 13:45:47Z 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"""
20from waeup.kofa.students.export import DataForLecturerExporter
21from kofacustom.unidel.students.interfaces import (
22    ICustomStudent,
23    ICustomStudentStudyCourse,
24    ICustomStudentStudyLevel,
25    ICustomCourseTicket,
26    ICustomStudentOnlinePayment)
27from kofacustom.nigeria.students.export import (
28    NigeriaStudentExporter,
29    NigeriaStudentStudyCourseExporter,
30    NigeriaStudentStudyLevelExporter,
31    NigeriaCourseTicketExporter,
32    NigeriaStudentPaymentExporter)
33from waeup.kofa.utils.helpers import iface_names
34
35class CustomStudentExporter(NigeriaStudentExporter):
36    """Exporter for Students.
37    """
38
39    fields = tuple(sorted(iface_names(
40        ICustomStudent, omit=['loggerInfo']))) + (
41        'password', 'state', 'history', 'certcode', 'is_postgrad',
42        'current_level', 'current_session')
43
44class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
45    """Exporter for StudentStudyCourses.
46    """
47
48    fields = tuple(
49        sorted(iface_names(ICustomStudentStudyCourse))) + ('student_id',)
50
51class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
52    """Exporter for StudentStudyLevels.
53    """
54    #: Fieldnames considered by this exporter
55    fields = tuple(sorted(iface_names(
56        ICustomStudentStudyLevel))) + (
57        'student_id', 'number_of_tickets','certcode', 'cgpa',
58        'matric_number', 'display_fullname')
59
60    def mangle_value(self, value, name, context=None):
61        """The mangler determines the student's id and fullname.
62        """
63        if context is not None:
64            student = context.student
65            if name in ('cgpa',) and student is not None:
66                value = context.cumulative_params[0]
67            if name in ('matric_number', 'display_fullname'):
68                value = getattr(student, name, None)
69        return super(
70            CustomStudentStudyLevelExporter, self).mangle_value(
71            value, name, context=context)
72
73
74class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
75    """Exporter for CourseTickets.
76    """
77
78    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
79        ['level', 'code', 'level_session'])) + ('student_id',
80        'certcode', 'display_fullname')
81
82class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
83    """Exporter for OnlinePayment instances.
84    """
85
86    fields = tuple(
87        sorted(iface_names(
88            ICustomStudentOnlinePayment, exclude_attribs=False,
89            omit=['display_item']))) + (
90            'student_id','state','current_session')
91
92class CustomDataForLecturerExporter(DataForLecturerExporter):
93    """The Data for Lecturer Exporter searches for students in the course
94    tickets catalog and exports those course tickets which belong to the
95    given course code, meet level and session passed through at the
96    same time, and which are editable by lecturers (disabled on 10/03/21).
97    This exporter can only be called at course level in the academic section.
98    """
99
100    fields = ('matric_number', 'student_id', 'display_fullname',
101              'faccode', 'certcode', 'state',
102              'level', 'code', 'level_session', 'score')
103
104    def mangle_value(self, value, name, context=None):
105        """The mangler determines the student's id and fullname.
106        """
107        if context is not None:
108            student = context.student
109            if name in ('matric_number',
110                        'reg_number',
111                        'student_id',
112                        'display_fullname',
113                        'faccode',
114                        'certcode',
115                        'state',) and student is not None:
116                value = getattr(student, name, None)
117        return super(
118            DataForLecturerExporter, self).mangle_value(
119            value, name, context=context)
120
Note: See TracBrowser for help on using the repository browser.