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

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

Export also matric number.

File size: 10.0 KB
RevLine 
[12856]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"""
[16390]20import grok
[17905]21import os
[15025]22from datetime import datetime
[17905]23from waeup.kofa.interfaces import (
24    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
[17862]25from zope.component import getUtility
[12856]26from waeup.uniben.students.interfaces import (
27    ICustomStudent,
28    ICustomStudentStudyCourse,
29    ICustomStudentStudyLevel,
30    ICustomCourseTicket,
[16390]31    ICustomStudentOnlinePayment,
32    IMedicalHistory)
[12856]33from kofacustom.nigeria.students.export import (
34    NigeriaStudentExporter,
35    NigeriaStudentStudyCourseExporter,
36    NigeriaStudentStudyLevelExporter,
37    NigeriaCourseTicketExporter,
[14856]38    NigeriaStudentPaymentExporter,
[15025]39    NigeriaDataForBursaryExporter,
[16498]40    NigeriaTrimmedDataExporter,
[15025]41    )
[16390]42from waeup.kofa.students.export import (
43    SchoolFeePaymentsOverviewExporter, StudentExporterBase)
[12856]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
[16498]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',
[17776]71        'perm_address',
[16498]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',
[17624]84        'lg_area',
[17785]85        'flash_notice',
[17806]86        'physical_clearance_date',
87        'former_matric',
88        'hq_matric_no',
[17905]89        'hq2_matric_no',
[17919]90        )
[16498]91
[17919]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)
[17905]104
105
[12856]106class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter):
107    """Exporter for StudentStudyCourses.
108    """
109
110    fields = tuple(
[16837]111        sorted(iface_names(ICustomStudentStudyCourse))) + (
112            'student_id', 'previous')
[12856]113
114class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter):
115    """Exporter for StudentStudyLevels.
116    """
117    #: Fieldnames considered by this exporter
118    fields = tuple(sorted(iface_names(
[12879]119        ICustomStudentStudyLevel))) + (
[16837]120        'student_id', 'number_of_tickets','certcode', 'previous')
[12856]121
122class CustomCourseTicketExporter(NigeriaCourseTicketExporter):
123    """Exporter for CourseTickets.
124    """
125
126    fields = tuple(sorted(iface_names(ICustomCourseTicket) +
127        ['level', 'code', 'level_session'])) + ('student_id',
[17558]128        'certcode', 'display_fullname', 'previous', 'matric_number')
[12856]129
[12879]130class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter):
[12856]131    """Exporter for OnlinePayment instances.
132    """
133
134    fields = tuple(
135        sorted(iface_names(
136            ICustomStudentOnlinePayment, exclude_attribs=False,
[13621]137            omit=['display_item']))) + (
[12856]138            'student_id','state','current_session')
139
[14856]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')
[15025]153
[15048]154class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter):
[15025]155
156    curr_year = datetime.now().year
[15044]157    year_range = range(curr_year - 14, curr_year + 1) # 3 more years in Uniben
[15025]158    year_range_tuple = tuple([str(year) for year in year_range])
159
[16476]160    fields = ('student_id', 'matric_number', 'firstname', 'middlename',
161        'lastname', 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
[15025]162        'current_level', 'current_session', 'current_mode',
[16498]163        'entry_session', 'reg_number', 'email2', 'sex'
[15025]164        ) + year_range_tuple
[16390]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',
[17395]175            'depcode', 'state','current_session', 'current_level', 'genotype', 'bloodgroup')
[16390]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',
[17395]188                'current_level',
189                'genotype', 'bloodgroup') and student is not None:
[16390]190                value = getattr(student, name, None)
191        return super(
192            MedicalHistoryExporter, self).mangle_value(
193            value, name, context=context)
[17396]194
[17915]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
[17396]206
[17915]207class RoutingSlipExporter(grok.GlobalUtility, StudentExporterBase):
208    """
209    """
210    grok.name('routingslip')
211
[17929]212    fields = ('student_id', 'matric_number',)
[17915]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
[17396]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',
[17897]246        'email',
247        'email2',
248        'phone',
[17396]249        'nationality',
250        'date_of_birth',
251        'state',
[17834]252        'lg_state',
253        'lg_area',
[17396]254        'current_mode',
[17862]255        'certificate',
[17396]256        'faccode',
257        'depcode',
258        'current_level',
259        'current_session',
260        'current_verdict',
[17831]261        'entry_session',
[17852]262        'nysc_verdict',
[17827]263        'nysc_senate_info',
264        'nysc_date_of_graduation',
265        'nysc_updated',
[17835]266        'nysc_processed',
[17396]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:
[17835]273            if student.nysc == True and student.nysc_processed == False:
[17396]274                students.append(student)
[17834]275        return students
276
277    def mangle_value(self, value, name, context=None):
[17862]278        verdicts = getUtility(IKofaUtils).VERDICTS_DICT
[17849]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:])
[17862]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]
[17834]293        return super(
294            NYSCExporter, self).mangle_value(
295            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.