source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/export.py @ 17857

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

Extend exporter.

File size: 4.3 KB
RevLine 
[13861]1## $Id: export.py 13544 2015-12-16 06:07:20Z henrik $
2##
3## Copyright (C) 2012 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 applicant-related stuff.
19"""
20import grok
21from waeup.kofa.applicants.interfaces import IApplicantBaseData
[14851]22from waeup.kofa.applicants.export import ApplicantPaymentExporter
[13984]23from waeup.kofa.utils.helpers import iface_names
[17857]24from kofacustom.nigeria.applicants.export import (NigeriaApplicantExporter,
25    NigeriaApplicantPaymentExporter)
[13861]26from kofacustom.nigeria.applicants.interfaces import (
[14020]27    INigeriaUGApplicant, INigeriaPGApplicant, IBankAccount)
[16078]28from waeup.uniben.applicants.interfaces import (
[16843]29    IUnibenRegistration, ITranscriptApplicant, IFrenchApplicant)
[13861]30
31class CustomApplicantExporter(NigeriaApplicantExporter):
32    """Exporter for Nigeria Applicants.
33    """
34
35    fields = tuple(sorted(set(
[13984]36        iface_names(INigeriaUGApplicant) +
37        iface_names(INigeriaPGApplicant) +
38        iface_names(IApplicantBaseData) +
[14020]39        iface_names(IUnibenRegistration) +
[16078]40        iface_names(ITranscriptApplicant) +
[16843]41        iface_names(IFrenchApplicant) +
[14020]42        iface_names(IBankAccount)
[13984]43        ))) + (
44        'password', 'state', 'history', 'container_code', 'application_number',
45        'display_fullname', 'application_date')
[13861]46
[17857]47class CustomApplicantPaymentExporter(NigeriaApplicantPaymentExporter):
[14851]48    """Exporter for OnlinePayment instances.
49    """
50
51    @property
52    def fields(self):
[17857]53        return super(CustomApplicantPaymentExporter, self).fields
[16317]54
55class PGApplicantExporter(NigeriaApplicantExporter):
56    """Exports pg applicants only.
57    """
58
59    grok.name('pg_applicants')
60    title = 'PG Applicants'
61
62    def is_postgrad(self, applicant):
63        course_studied = getattr(applicant, 'course_studied', None)
[16318]64        if course_studied is not None and (
65              course_studied.study_mode.startswith('pg')
[16317]66              or course_studied.study_mode.startswith('special_pg')):
67            return True
68        return False
69
70    def export(self, applicants, filepath=None):
71        """
72        """
73        writer, outfile = self.get_csv_writer(filepath)
74        for applicant in applicants:
75            if self.is_postgrad(applicant):
76                self.write_item(applicant, writer)
77        return self.close_outfile(filepath, outfile)
[16855]78
79class FrenchApplicantExporter(CustomApplicantExporter):
80    """
[16885]81    """
[16855]82
83    grok.name('flc_applicants')
84    title = 'FLC Applicants'
85
86    fields = tuple(sorted(set(
87        iface_names(IFrenchApplicant)
88        ))) + (
89        'password', 'state', 'history', 'container_code', 'application_number',
90        'display_fullname', 'application_date')
[16856]91
92    def export(self, applicants, filepath=None):
93        """Exports flc applicants only
94        """
95        writer, outfile = self.get_csv_writer(filepath)
96        for applicant in applicants:
97            if applicant.__parent__.code.startswith('flc'):
98                self.write_item(applicant, writer)
99        return self.close_outfile(filepath, outfile)
[16885]100
101class TranscriptApplicantExporter(CustomApplicantExporter):
102    """
103    """
104
105    grok.name('tsc_applicants')
106    title = 'Transcript Applicants'
107
108    fields = tuple(sorted(set(
109        iface_names(ITranscriptApplicant)
110        ))) + (
111        'password', 'state', 'history', 'container_code', 'application_number',
112        'display_fullname', 'application_date')
113
114    def export(self, applicants, filepath=None):
115        """Exports tsc applicants only
116        """
117        writer, outfile = self.get_csv_writer(filepath)
118        for applicant in applicants:
119            if applicant.__parent__.code.startswith('tsc'):
120                self.write_item(applicant, writer)
121        return self.close_outfile(filepath, outfile)
Note: See TracBrowser for help on using the repository browser.