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

Last change on this file was 17965, checked in by Henrik Bettermann, 4 weeks ago

Add exporter.

File size: 5.1 KB
Line 
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
22from waeup.kofa.applicants.export import ApplicantPaymentExporter
23from waeup.kofa.utils.helpers import iface_names
24from kofacustom.nigeria.applicants.export import (NigeriaApplicantExporter,
25    NigeriaApplicantPaymentExporter)
26from kofacustom.nigeria.applicants.interfaces import (
27    INigeriaUGApplicant, INigeriaPGApplicant, IBankAccount)
28from waeup.uniben.applicants.interfaces import (
29    IUnibenRegistration, ITranscriptApplicant,
30    IFrenchApplicant, IAfrimalApplicant)
31
32class CustomApplicantExporter(NigeriaApplicantExporter):
33    """Exporter for Nigeria Applicants.
34    """
35
36    fields = tuple(sorted(set(
37        iface_names(INigeriaUGApplicant) +
38        iface_names(INigeriaPGApplicant) +
39        iface_names(IApplicantBaseData) +
40        iface_names(IUnibenRegistration) +
41        iface_names(ITranscriptApplicant) +
42        iface_names(IFrenchApplicant) +
43        iface_names(IAfrimalApplicant) +
44        iface_names(IBankAccount)
45        ))) + (
46        'password', 'state', 'history', 'container_code', 'application_number',
47        'display_fullname', 'application_date')
48
49class CustomApplicantPaymentExporter(NigeriaApplicantPaymentExporter):
50    """Exporter for OnlinePayment instances.
51    """
52
53    @property
54    def fields(self):
55        return super(CustomApplicantPaymentExporter, self).fields
56
57class PGApplicantExporter(NigeriaApplicantExporter):
58    """Exports pg applicants only.
59    """
60
61    grok.name('pg_applicants')
62    title = 'PG Applicants'
63
64    def is_postgrad(self, applicant):
65        course_studied = getattr(applicant, 'course_studied', None)
66        if course_studied is not None and (
67              course_studied.study_mode.startswith('pg')
68              or course_studied.study_mode.startswith('special_pg')):
69            return True
70        return False
71
72    def export(self, applicants, filepath=None):
73        """
74        """
75        writer, outfile = self.get_csv_writer(filepath)
76        for applicant in applicants:
77            if self.is_postgrad(applicant):
78                self.write_item(applicant, writer)
79        return self.close_outfile(filepath, outfile)
80
81class FrenchApplicantExporter(CustomApplicantExporter):
82    """
83    """
84
85    grok.name('flc_applicants')
86    title = 'FLC Applicants'
87
88    fields = tuple(sorted(set(
89        iface_names(IFrenchApplicant)
90        ))) + (
91        'password', 'state', 'history', 'container_code', 'application_number',
92        'display_fullname', 'application_date')
93
94    def export(self, applicants, filepath=None):
95        """Exports flc applicants only
96        """
97        writer, outfile = self.get_csv_writer(filepath)
98        for applicant in applicants:
99            if applicant.__parent__.code.startswith('flc'):
100                self.write_item(applicant, writer)
101        return self.close_outfile(filepath, outfile)
102
103class AfrimalApplicantExporter(CustomApplicantExporter):
104    """
105    """
106
107    grok.name('afrimal_applicants')
108    title = 'AFRIMAL Applicants'
109
110    fields = tuple(sorted(set(
111        iface_names(IAfrimalApplicant)
112        ))) + (
113        'password', 'state', 'history', 'container_code', 'application_number',
114        'display_fullname', 'application_date')
115
116    def export(self, applicants, filepath=None):
117        """Exports afrimal applicants only
118        """
119        writer, outfile = self.get_csv_writer(filepath)
120        for applicant in applicants:
121            if applicant.__parent__.code.startswith('afrimal'):
122                self.write_item(applicant, writer)
123        return self.close_outfile(filepath, outfile)
124
125class TranscriptApplicantExporter(CustomApplicantExporter):
126    """
127    """
128
129    grok.name('tsc_applicants')
130    title = 'Transcript Applicants'
131
132    fields = tuple(sorted(set(
133        iface_names(ITranscriptApplicant)
134        ))) + (
135        'password', 'state', 'history', 'container_code', 'application_number',
136        'display_fullname', 'application_date')
137
138    def export(self, applicants, filepath=None):
139        """Exports tsc applicants only
140        """
141        writer, outfile = self.get_csv_writer(filepath)
142        for applicant in applicants:
143            if applicant.__parent__.code.startswith('tsc'):
144                self.write_item(applicant, writer)
145        return self.close_outfile(filepath, outfile)
Note: See TracBrowser for help on using the repository browser.