source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/export.py @ 16752

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

Export codes.

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1## $Id: export.py 16690 2021-10-29 17:19:52Z henrik $
2##
3## Copyright (C) 2014 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 (
22    IApplicantBaseData, IApplicantOnlinePayment)
23from waeup.kofa.utils.helpers import iface_names
24from waeup.kofa.applicants.export import ApplicantPaymentExporter
25from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter
26from kofacustom.nigeria.applicants.interfaces import (
27    INigeriaUGApplicant, INigeriaPGApplicant)
28from kofacustom.dspg.applicants.interfaces import (
29    ICustomUGApplicant, ICustomPGApplicant, ICustomSpecialApplicant)
30
31class CustomApplicantExporter(NigeriaApplicantExporter):
32    """Exporter for Custom Applicants.
33    """
34
35    fields = tuple(sorted(set(
36        iface_names(ICustomUGApplicant) +
37        iface_names(ICustomPGApplicant) +
38        iface_names(ICustomSpecialApplicant) +
39        iface_names(INigeriaUGApplicant) +
40        iface_names(INigeriaPGApplicant) +
41        iface_names(IApplicantBaseData)
42        ))) + (
43        'password', 'state', 'history', 'container_code', 'application_number',
44        'display_fullname', 'application_date', 'faculty', 'department')
45
46    def mangle_value(self, value, name, context=None):
47        """
48        """
49        if name == 'certificate' and value is not None:
50            value = value.code
51        if name == 'department':
52            cert = getattr(context, 'certificate')
53            if cert is not None:
54                value = cert.__parent__.__parent__.code
55        if name == 'faculty':
56            cert = getattr(context, 'certificate')
57            if cert is not None:
58                value = cert.__parent__.__parent__.__parent__.code
59        return super(
60            CustomApplicantExporter, self).mangle_value(
61            value, name, context=context)
62
63class CustomApplicantPaymentExporter(ApplicantPaymentExporter):
64    """
65    """
66    fields = tuple(sorted(iface_names(
67        IApplicantOnlinePayment,
68        exclude_attribs=False,
69        omit=['display_item']))) + (
70              'applicant_id',
71              'reg_number',
72              'display_fullname',
73              'course1',
74              'course2')
75
76    def mangle_value(self, value, name, context=None):
77        """
78        """
79        if name in ('applicant_id', 'reg_number',
80            'display_fullname') and context is not None:
81            applicant = context.__parent__
82            value = getattr(applicant, name, None)
83        if name in ('course1', 'course2') and context is not None:
84            applicant = context.__parent__
85            value = getattr(getattr(applicant, name, None), 'code', None)
86        return super(
87            CustomApplicantPaymentExporter, self).mangle_value(
88            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.