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

Last change on this file since 12503 was 12392, checked in by Henrik Bettermann, 10 years ago

Export email address and phone number.

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1## $Id: export.py 12392 2015-01-04 06:04:25Z 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    StudentPaymentsExporter)
34from waeup.kofa.utils.helpers import iface_names
35from kofacustom.nigeria.interfaces import MessageFactory as _
36
37class NigeriaStudentExporter(StudentExporter):
38    """Exporter for Students.
39    """
40
41    #: Fieldnames considered by this exporter
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    #: Fieldnames considered by this exporter
59    fields = tuple(
60        sorted(iface_names(INigeriaStudentStudyCourse))) + ('student_id',)
61
62class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter):
63    """Exporter for StudentStudyLevels.
64    """
65    #: Fieldnames considered by this exporter
66    fields = tuple(sorted(iface_names(
67        INigeriaStudentStudyLevel) + ['level'])) + (
68        'student_id', 'number_of_tickets','certcode')
69
70class NigeriaCourseTicketExporter(CourseTicketExporter):
71    """Exporter for CourseTickets.
72    """
73
74    #: Fieldnames considered by this exporter
75    fields = tuple(sorted(iface_names(INigeriaCourseTicket) +
76        ['level', 'code', 'level_session'])) + ('student_id',
77        'certcode', 'display_fullname')
78
79class NigeriaStudentPaymentsExporter(StudentPaymentsExporter):
80    """Exporter for OnlinePayment instances.
81    """
82
83    #: Fieldnames considered by this exporter
84    fields = tuple(
85        sorted(iface_names(
86            INigeriaStudentOnlinePayment, exclude_attribs=False,
87            omit=['display_item']))) + (
88            'student_id','state','current_session')
89
90class ClearanceRequestedStudentExporter(StudentExporter):
91    """Exporter of data used to assign physical clearance dates.
92    """
93
94    grok.name('clearancerequested')
95
96    fields = ('student_id', 'reg_number', 'display_fullname',
97              'state', 'current_session', 'history', 'physical_clearance_date',
98              'email','phone')
99
100    title = _(u'Clearance Invitation Data')
101
102    def filter_func(self, x, **kw):
103        # We use this method to post-filter students in state
104        # 'clearance_requested'
105        return [student for student in x if student.state == REQUESTED]
106
107    def mangle_value(self, value, name, context=None):
108        if name == 'history':
109            # Only show last mesage
110            value = value.messages[-1]
111        return super(
112            StudentExporter, self).mangle_value(
113            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.