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

Last change on this file since 17384 was 16885, checked in by Henrik Bettermann, 3 years ago

Implement TranscriptApplicantExporter?.

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
[13861]24from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter
25from kofacustom.nigeria.applicants.interfaces import (
[14020]26    INigeriaUGApplicant, INigeriaPGApplicant, IBankAccount)
[16078]27from waeup.uniben.applicants.interfaces import (
[16843]28    IUnibenRegistration, ITranscriptApplicant, IFrenchApplicant)
[13861]29
30class CustomApplicantExporter(NigeriaApplicantExporter):
31    """Exporter for Nigeria Applicants.
32    """
33
34    fields = tuple(sorted(set(
[13984]35        iface_names(INigeriaUGApplicant) +
36        iface_names(INigeriaPGApplicant) +
37        iface_names(IApplicantBaseData) +
[14020]38        iface_names(IUnibenRegistration) +
[16078]39        iface_names(ITranscriptApplicant) +
[16843]40        iface_names(IFrenchApplicant) +
[14020]41        iface_names(IBankAccount)
[13984]42        ))) + (
43        'password', 'state', 'history', 'container_code', 'application_number',
44        'display_fullname', 'application_date')
[13861]45
[14851]46class CustomApplicantPaymentExporter(ApplicantPaymentExporter):
47    """Exporter for OnlinePayment instances.
48    """
49
50    @property
51    def fields(self):
52        return super(CustomApplicantPaymentExporter, self).fields + (
53            'r_pay_reference',)
[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.