source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/export.py @ 16425

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

Export error message.

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1## $Id: export.py 16425 2021-03-22 21:51:50Z 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
21import sys
22from waeup.kofa.applicants.interfaces import IApplicantBaseData
23from waeup.kofa.utils.helpers import iface_names
24from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter
25from kofacustom.nigeria.applicants.interfaces import INigeriaUGApplicant
26from waeup.fceokene.applicants.interfaces import (
27    ICustomUGApplicant, ITPURegistration)
28from waeup.fceokene.applicants.schools import SCHOOLS
29
30class CustomApplicantExporter(NigeriaApplicantExporter):
31    """Exporter for Nigeria Applicants.
32    """
33
34    fields = tuple(sorted(set(
35        iface_names(ICustomUGApplicant) +
36        iface_names(INigeriaUGApplicant) +
37        iface_names(IApplicantBaseData) +
38        iface_names(ITPURegistration)
39        ))) + (
40        'password', 'state', 'history', 'container_code', 'application_number',
41        'display_fullname', 'application_date',
42        'school_name1', 'school_name2', 'school_name3')
43
44    def mangle_value(self, value, name, context=None):
45        """The mangler determines the codes of the atributes `course1`,
46        `course2` and `course_admitted`. It furthermore prepares the
47        history messages and adds a hash symbol at the end of the phone number
48        to avoid annoying automatic number transformation by Excel or Calc.
49        """
50        if name.startswith('school_name'):
51            value = getattr(context, name.replace('_name', ''), None)
52            if value:
53                try:
54                    value = '%s - %s - %s' % (
55                        SCHOOLS[value][0], SCHOOLS[value][1], SCHOOLS[value][2])
56                except:
57                    value = "%s: %s" % (sys.exc_info()[0], sys.exc_info()[1])
58        return super(
59            CustomApplicantExporter, self).mangle_value(
60            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.