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

Last change on this file since 15554 was 15351, checked in by Henrik Bettermann, 6 years ago

Add lga to NigeriaDataForBursaryExporter?.

Adjust tests.

  • Property svn:keywords set to Id
File size: 5.0 KB
RevLine 
[9042]1## $Id: export.py 15351 2019-03-11 20:43:33Z 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,
34    DataForBursaryExporter)
[9042]35from waeup.kofa.utils.helpers import iface_names
[12107]36from kofacustom.nigeria.interfaces import MessageFactory as _
[9042]37
[12080]38class NigeriaStudentExporter(StudentExporter):
[9042]39    """Exporter for Students.
40    """
41
42    fields = tuple(sorted(iface_names(
43        INigeriaStudent, omit=['loggerInfo']))) + (
[9254]44        'password', 'state', 'history', 'certcode', 'is_postgrad',
45        'current_level', 'current_session')
[9042]46
[9044]47    def mangle_value(self, value, name, context=None):
48        if '_result' in name and value:
49            value = [eval(entry.to_string()) for entry in value]
50        return super(
[12080]51            NigeriaStudentExporter, self).mangle_value(
[9044]52            value, name, context=context)
[9042]53
54class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter):
55    """Exporter for StudentStudyCourses.
56    """
57
58    fields = tuple(
59        sorted(iface_names(INigeriaStudentStudyCourse))) + ('student_id',)
60
[11544]61class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter):
62    """Exporter for StudentStudyLevels.
63    """
64    fields = tuple(sorted(iface_names(
[12875]65        INigeriaStudentStudyLevel))) + (
[11544]66        'student_id', 'number_of_tickets','certcode')
[9042]67
68class NigeriaCourseTicketExporter(CourseTicketExporter):
69    """Exporter for CourseTickets.
70    """
71
72    fields = tuple(sorted(iface_names(INigeriaCourseTicket) +
[11491]73        ['level', 'code', 'level_session'])) + ('student_id',
74        'certcode', 'display_fullname')
[10757]75
[12875]76class NigeriaStudentPaymentExporter(StudentPaymentExporter):
[10757]77    """Exporter for OnlinePayment instances.
78    """
79
80    fields = tuple(
81        sorted(iface_names(
82            INigeriaStudentOnlinePayment, exclude_attribs=False,
[13623]83            omit=['display_item','formatted_p_date']))) + (
[10757]84            'student_id','state','current_session')
[12107]85
[13944]86class NigeriaDataForBursaryExporter(DataForBursaryExporter):
87    """Exporter for bursary data.
88    """
89
90    fields = tuple(
91        sorted(iface_names(
92            INigeriaStudentOnlinePayment, exclude_attribs=False,
93            omit=['display_item', 'certificate', 'student']))) + (
94            'student_id','matric_number','reg_number',
95            'firstname', 'middlename', 'lastname',
96            'state','current_session',
97            'entry_session', 'entry_mode',
[15351]98            'faccode', 'depcode','certcode','lga')
[13944]99
[15351]100    def mangle_value(self, value, name, context=None):
101        """The mangler fetches the student data.
102        """
103        if context is not None:
104            student = context.student
105            if name in [
106                'student_id','matric_number', 'reg_number',
107                'firstname', 'middlename', 'lastname',
108                'state', 'current_session',
109                'entry_session', 'entry_mode',
110                'faccode', 'depcode', 'certcode',
111                'lga'] and student is not None:
112                value = getattr(student, name, None)
113        return super(
114            StudentPaymentExporter, self).mangle_value(
115            value, name, context=context)
116
[12107]117class ClearanceRequestedStudentExporter(StudentExporter):
[12120]118    """Exporter of data used to assign physical clearance dates.
[12107]119    """
120
121    grok.name('clearancerequested')
122
123    fields = ('student_id', 'reg_number', 'display_fullname',
[12392]124              'state', 'current_session', 'history', 'physical_clearance_date',
125              'email','phone')
[12107]126
127    title = _(u'Clearance Invitation Data')
128
129    def filter_func(self, x, **kw):
130        # We use this method to post-filter students in state
131        # 'clearance_requested'
132        return [student for student in x if student.state == REQUESTED]
133
134    def mangle_value(self, value, name, context=None):
135        if name == 'history':
136            # Only show last mesage
137            value = value.messages[-1]
138        return super(
139            StudentExporter, self).mangle_value(
140            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.