[9042] | 1 | ## $Id: export.py 12875 2015-04-23 19:39:04Z 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] | 20 | import grok |
---|
| 21 | from waeup.kofa.interfaces import REQUESTED |
---|
[9042] | 22 | from kofacustom.nigeria.students.interfaces import ( |
---|
[11544] | 23 | INigeriaStudent, |
---|
| 24 | INigeriaStudentStudyCourse, |
---|
| 25 | INigeriaStudentStudyLevel, |
---|
| 26 | INigeriaCourseTicket, |
---|
[10757] | 27 | INigeriaStudentOnlinePayment) |
---|
[9042] | 28 | from waeup.kofa.students.export import ( |
---|
[12080] | 29 | StudentExporter, |
---|
[11544] | 30 | StudentStudyCourseExporter, |
---|
| 31 | StudentStudyLevelExporter, |
---|
| 32 | CourseTicketExporter, |
---|
[12875] | 33 | StudentPaymentExporter) |
---|
[9042] | 34 | from waeup.kofa.utils.helpers import iface_names |
---|
[12107] | 35 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
[9042] | 36 | |
---|
[12080] | 37 | class NigeriaStudentExporter(StudentExporter): |
---|
[9042] | 38 | """Exporter for Students. |
---|
| 39 | """ |
---|
| 40 | |
---|
| 41 | #: Fieldnames considered by this exporter |
---|
| 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 | |
---|
| 54 | class 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 | |
---|
[11544] | 62 | class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter): |
---|
| 63 | """Exporter for StudentStudyLevels. |
---|
| 64 | """ |
---|
| 65 | #: Fieldnames considered by this exporter |
---|
| 66 | fields = tuple(sorted(iface_names( |
---|
[12875] | 67 | INigeriaStudentStudyLevel))) + ( |
---|
[11544] | 68 | 'student_id', 'number_of_tickets','certcode') |
---|
[9042] | 69 | |
---|
| 70 | class NigeriaCourseTicketExporter(CourseTicketExporter): |
---|
| 71 | """Exporter for CourseTickets. |
---|
| 72 | """ |
---|
| 73 | |
---|
| 74 | #: Fieldnames considered by this exporter |
---|
| 75 | fields = tuple(sorted(iface_names(INigeriaCourseTicket) + |
---|
[11491] | 76 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
| 77 | 'certcode', 'display_fullname') |
---|
[10757] | 78 | |
---|
[12875] | 79 | class NigeriaStudentPaymentExporter(StudentPaymentExporter): |
---|
[10757] | 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') |
---|
[12107] | 89 | |
---|
| 90 | class ClearanceRequestedStudentExporter(StudentExporter): |
---|
[12120] | 91 | """Exporter of data used to assign physical clearance dates. |
---|
[12107] | 92 | """ |
---|
| 93 | |
---|
| 94 | grok.name('clearancerequested') |
---|
| 95 | |
---|
| 96 | fields = ('student_id', 'reg_number', 'display_fullname', |
---|
[12392] | 97 | 'state', 'current_session', 'history', 'physical_clearance_date', |
---|
| 98 | 'email','phone') |
---|
[12107] | 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) |
---|