source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/export.py @ 17811

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

Adjust to base package.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: export.py 16832 2022-02-24 11:11:58Z 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 waeup.kofa.interfaces import REQUESTED
22from kofacustom.nigeria.students.interfaces import (
23    INigeriaStudent,
24    INigeriaStudentStudyCourse,
25    INigeriaStudentStudyLevel,
26    INigeriaCourseTicket,
27    INigeriaStudentOnlinePayment)
28from waeup.kofa.students.export import (
29    StudentExporter,
30    StudentStudyCourseExporter,
31    StudentStudyLevelExporter,
32    CourseTicketExporter,
33    StudentPaymentExporter,
34    DataForBursaryExporter,
35    TrimmedDataExporter)
36from waeup.kofa.utils.helpers import iface_names
37from kofacustom.nigeria.interfaces import MessageFactory as _
38
39class NigeriaStudentExporter(StudentExporter):
40    """Exporter for Students.
41    """
42
43    fields = tuple(sorted(iface_names(
44        INigeriaStudent, omit=['loggerInfo']))) + (
45        'password', 'state', 'history', 'certcode', 'is_postgrad',
46        'current_level', 'current_session')
47
48    def mangle_value(self, value, name, context=None):
49        if '_result' in name and value:
50            value = [eval(entry.to_string()) for entry in value]
51        return super(
52            NigeriaStudentExporter, self).mangle_value(
53            value, name, context=context)
54
55class NigeriaTrimmedDataExporter(TrimmedDataExporter):
56    """The Student Trimmed Data Exporter first filters the set of students
57    by searching the students catalog. Then it exports a trimmed data set
58    of this set of students.
59    """
60
61    fields = (
62        'student_id',
63        'matric_number',
64        'reg_number',
65        'firstname',
66        'middlename',
67        'lastname',
68        'sex',
69        'email',
70        'phone',
71        'nationality',
72        'date_of_birth',
73        'state',
74        'current_mode',
75        'certcode',
76        'faccode',
77        'depcode',
78        'current_level',
79        'current_session',
80        'current_verdict',
81        'entry_session',
82        'lg_state',
83        'lg_area')
84
85    def mangle_value(self, value, name, context=None):
86        if name == 'lg_state' and context.lga:
87            value = context.lga.split('_')[0]
88        if name == 'lg_area' and context.lga:
89            value = '-'.join(context.lga.split('_')[1:])
90        return super(
91            NigeriaTrimmedDataExporter, self).mangle_value(
92            value, name, context=context)
93
94class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter):
95    """Exporter for StudentStudyCourses.
96    """
97
98    fields = tuple(
99        sorted(iface_names(INigeriaStudentStudyCourse))) + (
100            'student_id', 'previous')
101
102class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter):
103    """Exporter for StudentStudyLevels.
104    """
105    fields = tuple(sorted(iface_names(
106        INigeriaStudentStudyLevel))) + (
107        'student_id', 'number_of_tickets','certcode', 'previous')
108
109class NigeriaCourseTicketExporter(CourseTicketExporter):
110    """Exporter for CourseTickets.
111    """
112
113    fields = tuple(sorted(iface_names(INigeriaCourseTicket) +
114        ['level', 'code', 'level_session'])) + ('student_id',
115        'certcode', 'display_fullname', 'previous')
116
117class NigeriaStudentPaymentExporter(StudentPaymentExporter):
118    """Exporter for OnlinePayment instances.
119    """
120
121    fields = tuple(
122        sorted(iface_names(
123            INigeriaStudentOnlinePayment, exclude_attribs=False,
124            omit=['display_item','formatted_p_date']))) + (
125            'student_id','state','current_session')
126
127class NigeriaDataForBursaryExporter(DataForBursaryExporter):
128    """Exporter for bursary data.
129    """
130
131    fields = tuple(
132        sorted(iface_names(
133            INigeriaStudentOnlinePayment, exclude_attribs=False,
134            omit=['display_item', 'certificate', 'student']))) + (
135            'student_id','matric_number','reg_number',
136            'firstname', 'middlename', 'lastname','sex',
137            'state','current_session',
138            'entry_session', 'entry_mode',
139            'faccode', 'depcode','certcode','lga')
140
141    def mangle_value(self, value, name, context=None):
142        """The mangler fetches the student data.
143        """
144        if context is not None:
145            student = context.student
146            if name in [
147                'student_id','matric_number', 'reg_number',
148                'firstname', 'middlename', 'lastname','sex',
149                'state', 'current_session',
150                'entry_session', 'entry_mode',
151                'faccode', 'depcode', 'certcode',
152                'lga'] and student is not None:
153                value = getattr(student, name, None)
154        return super(
155            StudentPaymentExporter, self).mangle_value(
156            value, name, context=context)
157
158class ClearanceRequestedStudentExporter(StudentExporter):
159    """Exporter of data used to assign physical clearance dates.
160    """
161
162    grok.name('clearancerequested')
163
164    fields = ('student_id', 'reg_number', 'display_fullname',
165              'state', 'current_session', 'history', 'physical_clearance_date',
166              'email','phone')
167
168    title = _(u'Clearance Invitation Data')
169
170    def filter_func(self, x, **kw):
171        # We use this method to post-filter students in state
172        # 'clearance_requested'
173        return [student for student in x if student.state == REQUESTED]
174
175    def mangle_value(self, value, name, context=None):
176        if name == 'history':
177            # Only show last mesage
178            value = value.messages[-1]
179        return super(
180            StudentExporter, self).mangle_value(
181            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.