source: main/waeup.uniben/trunk/src/waeup/uniben/students/export.py @ 17903

Last change on this file since 17903 was 17897, checked in by Henrik Bettermann, 3 months ago

Add fields.

File size: 8.1 KB
Line 
1## $Id: export.py 12084 2014-11-28 09:54:10Z henrik $
2##
3## Copyright (C) 2015 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 datetime import datetime
22from waeup.kofa.interfaces import IKofaUtils
23from zope.component import getUtility
24from waeup.uniben.students.interfaces import (
25    ICustomStudent,
26    ICustomStudentStudyCourse,
27    ICustomStudentStudyLevel,
28    ICustomCourseTicket,
29    ICustomStudentOnlinePayment,
30    IMedicalHistory)
31from kofacustom.nigeria.students.export import (
32    NigeriaStudentExporter,
33    NigeriaStudentStudyCourseExporter,
34    NigeriaStudentStudyLevelExporter,
35    NigeriaCourseTicketExporter,
36    NigeriaStudentPaymentExporter,
37    NigeriaDataForBursaryExporter,
38    NigeriaTrimmedDataExporter,
39    )
40from waeup.kofa.students.export import (
41    SchoolFeePaymentsOverviewExporter, StudentExporterBase)
42from waeup.kofa.utils.helpers import iface_names
43
44class CustomStudentExporter(NigeriaStudentExporter):
45    """Exporter for Students.
46    """
47
48    fields = tuple(sorted(iface_names(
49        ICustomStudent, omit=['loggerInfo']))) + (
50        'password', 'state', 'history', 'certcode', 'is_postgrad',
51        'current_level', 'current_session')
52
53class CustomTrimmedDataExporter(NigeriaTrimmedDataExporter):
54    """The Student Trimmed Data Exporter first filters the set of students
55    by searching the students catalog. Then it exports a trimmed data set
56    of this set of students.
57    """
58    fields = (
59        'student_id',
60        'matric_number',
61        'reg_number',
62        'firstname',
63        'middlename',
64        'lastname',
65        'sex',
66        'email',
67        'email2',
68        'phone',
69        'perm_address',
70        'nationality',
71        'date_of_birth',
72        'state',
73        'current_mode',
74        'certcode',
75        'faccode',
76        'depcode',
77        'current_level',
78        'current_session',
79        'current_verdict',
80        'entry_session',
81        'lg_state',
82        'lg_area',
83        'flash_notice',
84        'physical_clearance_date',
85        'former_matric',
86        'hq_matric_no',
87        'hq2_matric_no')
88
89class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
90    """Exporter for StudentStudyCourses.
91    """
92
93    fields = tuple(
94        sorted(iface_names(ICustomStudentStudyCourse))) + (
95            'student_id', 'previous')
96
97class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
98    """Exporter for StudentStudyLevels.
99    """
100    #: Fieldnames considered by this exporter
101    fields = tuple(sorted(iface_names(
102        ICustomStudentStudyLevel))) + (
103        'student_id', 'number_of_tickets','certcode', 'previous')
104
105class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
106    """Exporter for CourseTickets.
107    """
108
109    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
110        ['level', 'code', 'level_session'])) + ('student_id',
111        'certcode', 'display_fullname', 'previous', 'matric_number')
112
113class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
114    """Exporter for OnlinePayment instances.
115    """
116
117    fields = tuple(
118        sorted(iface_names(
119            ICustomStudentOnlinePayment, exclude_attribs=False,
120            omit=['display_item']))) + (
121            'student_id','state','current_session')
122
123class CustomDataForBursaryExporter(NigeriaDataForBursaryExporter):
124    """
125    """
126
127    fields = tuple(
128        sorted(iface_names(
129            ICustomStudentOnlinePayment, exclude_attribs=False,
130            omit=['display_item', 'certificate', 'student']))) + (
131            'student_id','matric_number','reg_number',
132            'firstname', 'middlename', 'lastname',
133            'state','current_session',
134            'entry_session', 'entry_mode',
135            'faccode', 'depcode','certcode')
136
137class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter):
138
139    curr_year = datetime.now().year
140    year_range = range(curr_year - 14, curr_year + 1) # 3 more years in Uniben
141    year_range_tuple = tuple([str(year) for year in year_range])
142
143    fields = ('student_id', 'matric_number', 'firstname', 'middlename',
144        'lastname', 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
145        'current_level', 'current_session', 'current_mode',
146        'entry_session', 'reg_number', 'email2', 'sex'
147        ) + year_range_tuple
148
149class MedicalHistoryExporter(grok.GlobalUtility, StudentExporterBase):
150    """
151    """
152    grok.name('medicalhistory')
153
154    fields = tuple(
155        sorted(iface_names(
156            IMedicalHistory, exclude_attribs=False,))) + (
157            'student_id','display_fullname', 'matric_number', 'faccode',
158            'depcode', 'state','current_session', 'current_level', 'genotype', 'bloodgroup')
159    title = 'Medical Questionnaire Data'
160
161    def mangle_value(self, value, name, context=None):
162        """The mangler determines the titles of faculty, department
163        and certificate. It also computes the path of passport image file
164        stored in the filesystem.
165        """
166        if context is not None:
167            student = context.student
168            if name in ('student_id','display_fullname',
169                'matric_number', 'faccode',
170                'depcode', 'state','current_session',
171                'current_level',
172                'genotype', 'bloodgroup') and student is not None:
173                value = getattr(student, name, None)
174        return super(
175            MedicalHistoryExporter, self).mangle_value(
176            value, name, context=context)
177
178
179class NYSCExporter(SchoolFeePaymentsOverviewExporter):
180    """
181    """
182    grok.name('nysc')
183    curr_year = datetime.now().year
184    year_range = range(curr_year - 11, curr_year + 1)
185    year_range_tuple = tuple([str(year) for year in year_range])
186    fields = ('student_id',
187        'matric_number',
188        'reg_number',
189        'firstname',
190        'middlename',
191        'lastname',
192        'sex',
193        'email',
194        'email2',
195        'phone',
196        'nationality',
197        'date_of_birth',
198        'state',
199        'lg_state',
200        'lg_area',
201        'current_mode',
202        'certificate',
203        'faccode',
204        'depcode',
205        'current_level',
206        'current_session',
207        'current_verdict',
208        'entry_session',
209        'nysc_verdict',
210        'nysc_senate_info',
211        'nysc_date_of_graduation',
212        'nysc_updated',
213        'nysc_processed',
214        ) + year_range_tuple
215    title = u'NYSC Indication'
216
217    def filter_func(self, x, **kw):
218        students = list()
219        for student in x:
220            if student.nysc == True and student.nysc_processed == False:
221                students.append(student)
222        return students
223
224    def mangle_value(self, value, name, context=None):
225        verdicts = getUtility(IKofaUtils).VERDICTS_DICT
226        if name in ('lg_state', 'lg_area') and context.lga:
227            value = context.lga
228            if value.startswith('cross_river') or value.startswith('akwa_ibom'):
229                value = context.lga.replace('_', '-', 1)
230            if name == 'lg_state':
231                value = value.split('_')[0]
232            if name == 'lg_area':
233                value = '-'.join(value.split('_')[1:])
234        if name == 'certificate':
235            cert = getattr(context.get('studycourse', None), 'certificate', None)
236            if cert is not None:
237                value = cert.title
238        if name == 'nysc_verdict' and value:
239            value = verdicts[value]
240        return super(
241            NYSCExporter, self).mangle_value(
242            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.