[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 | """ |
---|
| 20 | import grok |
---|
| 21 | from waeup.kofa.applicants.interfaces import IApplicantBaseData |
---|
[14851] | 22 | from waeup.kofa.applicants.export import ApplicantPaymentExporter |
---|
[13984] | 23 | from waeup.kofa.utils.helpers import iface_names |
---|
[17857] | 24 | from kofacustom.nigeria.applicants.export import (NigeriaApplicantExporter, |
---|
| 25 | NigeriaApplicantPaymentExporter) |
---|
[13861] | 26 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
[14020] | 27 | INigeriaUGApplicant, INigeriaPGApplicant, IBankAccount) |
---|
[16078] | 28 | from waeup.uniben.applicants.interfaces import ( |
---|
[17965] | 29 | IUnibenRegistration, ITranscriptApplicant, |
---|
| 30 | IFrenchApplicant, IAfrimalApplicant) |
---|
[13861] | 31 | |
---|
| 32 | class CustomApplicantExporter(NigeriaApplicantExporter): |
---|
| 33 | """Exporter for Nigeria Applicants. |
---|
| 34 | """ |
---|
| 35 | |
---|
| 36 | fields = tuple(sorted(set( |
---|
[13984] | 37 | iface_names(INigeriaUGApplicant) + |
---|
| 38 | iface_names(INigeriaPGApplicant) + |
---|
| 39 | iface_names(IApplicantBaseData) + |
---|
[14020] | 40 | iface_names(IUnibenRegistration) + |
---|
[16078] | 41 | iface_names(ITranscriptApplicant) + |
---|
[16843] | 42 | iface_names(IFrenchApplicant) + |
---|
[17965] | 43 | iface_names(IAfrimalApplicant) + |
---|
[14020] | 44 | iface_names(IBankAccount) |
---|
[13984] | 45 | ))) + ( |
---|
| 46 | 'password', 'state', 'history', 'container_code', 'application_number', |
---|
| 47 | 'display_fullname', 'application_date') |
---|
[13861] | 48 | |
---|
[17857] | 49 | class CustomApplicantPaymentExporter(NigeriaApplicantPaymentExporter): |
---|
[14851] | 50 | """Exporter for OnlinePayment instances. |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | @property |
---|
| 54 | def fields(self): |
---|
[17857] | 55 | return super(CustomApplicantPaymentExporter, self).fields |
---|
[16317] | 56 | |
---|
| 57 | class 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) |
---|
[16318] | 66 | if course_studied is not None and ( |
---|
| 67 | course_studied.study_mode.startswith('pg') |
---|
[16317] | 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) |
---|
[16855] | 80 | |
---|
| 81 | class FrenchApplicantExporter(CustomApplicantExporter): |
---|
| 82 | """ |
---|
[16885] | 83 | """ |
---|
[16855] | 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') |
---|
[16856] | 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) |
---|
[16885] | 102 | |
---|
[17965] | 103 | class 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 | |
---|
[16885] | 125 | class 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) |
---|