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

Last change on this file since 17852 was 17852, checked in by Henrik Bettermann, 4 months ago

Change form.

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