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

Last change on this file since 17296 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
RevLine 
[9042]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"""
[12107]20import grok
21from waeup.kofa.interfaces import REQUESTED
[9042]22from kofacustom.nigeria.students.interfaces import (
[11544]23    INigeriaStudent,
24    INigeriaStudentStudyCourse,
25    INigeriaStudentStudyLevel,
26    INigeriaCourseTicket,
[10757]27    INigeriaStudentOnlinePayment)
[9042]28from waeup.kofa.students.export import (
[12080]29    StudentExporter,
[11544]30    StudentStudyCourseExporter,
31    StudentStudyLevelExporter,
32    CourseTicketExporter,
[13944]33    StudentPaymentExporter,
[16195]34    DataForBursaryExporter,
35    TrimmedDataExporter)
[9042]36from waeup.kofa.utils.helpers import iface_names
[12107]37from kofacustom.nigeria.interfaces import MessageFactory as _
[9042]38
[12080]39class NigeriaStudentExporter(StudentExporter):
[9042]40    """Exporter for Students.
41    """
42
43    fields = tuple(sorted(iface_names(
44        INigeriaStudent, omit=['loggerInfo']))) + (
[9254]45        'password', 'state', 'history', 'certcode', 'is_postgrad',
46        'current_level', 'current_session')
[9042]47
[9044]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(
[12080]52            NigeriaStudentExporter, self).mangle_value(
[9044]53            value, name, context=context)
[9042]54
[16195]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):
[16197]86        if name == 'lg_state' and context.lga:
[16195]87            value = context.lga.split('_')[0]
[16197]88        if name == 'lg_area' and context.lga:
[16195]89            value = '-'.join(context.lga.split('_')[1:])
90        return super(
91            NigeriaTrimmedDataExporter, self).mangle_value(
92            value, name, context=context)
93
[9042]94class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter):
95    """Exporter for StudentStudyCourses.
96    """
97
98    fields = tuple(
[16832]99        sorted(iface_names(INigeriaStudentStudyCourse))) + (
100            'student_id', 'previous')
[9042]101
[11544]102class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter):
103    """Exporter for StudentStudyLevels.
104    """
105    fields = tuple(sorted(iface_names(
[12875]106        INigeriaStudentStudyLevel))) + (
[16832]107        'student_id', 'number_of_tickets','certcode', 'previous')
[9042]108
109class NigeriaCourseTicketExporter(CourseTicketExporter):
110    """Exporter for CourseTickets.
111    """
112
113    fields = tuple(sorted(iface_names(INigeriaCourseTicket) +
[11491]114        ['level', 'code', 'level_session'])) + ('student_id',
[16832]115        'certcode', 'display_fullname', 'previous')
[10757]116
[12875]117class NigeriaStudentPaymentExporter(StudentPaymentExporter):
[10757]118    """Exporter for OnlinePayment instances.
119    """
120
121    fields = tuple(
122        sorted(iface_names(
123            INigeriaStudentOnlinePayment, exclude_attribs=False,
[13623]124            omit=['display_item','formatted_p_date']))) + (
[10757]125            'student_id','state','current_session')
[12107]126
[13944]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',
[16334]136            'firstname', 'middlename', 'lastname','sex',
[13944]137            'state','current_session',
138            'entry_session', 'entry_mode',
[15351]139            'faccode', 'depcode','certcode','lga')
[13944]140
[15351]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',
[16334]148                'firstname', 'middlename', 'lastname','sex',
[15351]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
[12107]158class ClearanceRequestedStudentExporter(StudentExporter):
[12120]159    """Exporter of data used to assign physical clearance dates.
[12107]160    """
161
162    grok.name('clearancerequested')
163
164    fields = ('student_id', 'reg_number', 'display_fullname',
[12392]165              'state', 'current_session', 'history', 'physical_clearance_date',
166              'email','phone')
[12107]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.