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

Last change on this file since 14828 was 13944, checked in by Henrik Bettermann, 9 years ago

Customize DataForBursaryExporter?.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1## $Id: export.py 13944 2016-06-15 08:43:43Z 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)
35from waeup.kofa.utils.helpers import iface_names
36from kofacustom.nigeria.interfaces import MessageFactory as _
37
38class NigeriaStudentExporter(StudentExporter):
39    """Exporter for Students.
40    """
41
42    fields = tuple(sorted(iface_names(
43        INigeriaStudent, omit=['loggerInfo']))) + (
44        'password', 'state', 'history', 'certcode', 'is_postgrad',
45        'current_level', 'current_session')
46
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(
51            NigeriaStudentExporter, self).mangle_value(
52            value, name, context=context)
53
54class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter):
55    """Exporter for StudentStudyCourses.
56    """
57
58    fields = tuple(
59        sorted(iface_names(INigeriaStudentStudyCourse))) + ('student_id',)
60
61class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter):
62    """Exporter for StudentStudyLevels.
63    """
64    fields = tuple(sorted(iface_names(
65        INigeriaStudentStudyLevel))) + (
66        'student_id', 'number_of_tickets','certcode')
67
68class NigeriaCourseTicketExporter(CourseTicketExporter):
69    """Exporter for CourseTickets.
70    """
71
72    fields = tuple(sorted(iface_names(INigeriaCourseTicket) +
73        ['level', 'code', 'level_session'])) + ('student_id',
74        'certcode', 'display_fullname')
75
76class NigeriaStudentPaymentExporter(StudentPaymentExporter):
77    """Exporter for OnlinePayment instances.
78    """
79
80    fields = tuple(
81        sorted(iface_names(
82            INigeriaStudentOnlinePayment, exclude_attribs=False,
83            omit=['display_item','formatted_p_date']))) + (
84            'student_id','state','current_session')
85
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',
98            'faccode', 'depcode','certcode')
99
100class ClearanceRequestedStudentExporter(StudentExporter):
101    """Exporter of data used to assign physical clearance dates.
102    """
103
104    grok.name('clearancerequested')
105
106    fields = ('student_id', 'reg_number', 'display_fullname',
107              'state', 'current_session', 'history', 'physical_clearance_date',
108              'email','phone')
109
110    title = _(u'Clearance Invitation Data')
111
112    def filter_func(self, x, **kw):
113        # We use this method to post-filter students in state
114        # 'clearance_requested'
115        return [student for student in x if student.state == REQUESTED]
116
117    def mangle_value(self, value, name, context=None):
118        if name == 'history':
119            # Only show last mesage
120            value = value.messages[-1]
121        return super(
122            StudentExporter, self).mangle_value(
123            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.