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

Last change on this file since 17959 was 17929, checked in by Henrik Bettermann, 2 months ago

Export also matric number.

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