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

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

Export codes.

  • Property svn:keywords set to Id
File size: 3.4 KB
RevLine 
[11543]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
[15513]21from waeup.kofa.applicants.interfaces import (
22    IApplicantBaseData, IApplicantOnlinePayment)
[13983]23from waeup.kofa.utils.helpers import iface_names
[15513]24from waeup.kofa.applicants.export import ApplicantPaymentExporter
[12084]25from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter
[11543]26from kofacustom.nigeria.applicants.interfaces import (
27    INigeriaUGApplicant, INigeriaPGApplicant)
[14716]28from kofacustom.dspg.applicants.interfaces import (
[15186]29    ICustomUGApplicant, ICustomPGApplicant, ICustomSpecialApplicant)
[11543]30
[12084]31class CustomApplicantExporter(NigeriaApplicantExporter):
[11543]32    """Exporter for Custom Applicants.
33    """
34
35    fields = tuple(sorted(set(
[13983]36        iface_names(ICustomUGApplicant) +
37        iface_names(ICustomPGApplicant) +
[15186]38        iface_names(ICustomSpecialApplicant) +
[13983]39        iface_names(INigeriaUGApplicant) +
40        iface_names(INigeriaPGApplicant) +
41        iface_names(IApplicantBaseData)
42        ))) + (
43        'password', 'state', 'history', 'container_code', 'application_number',
[16690]44        'display_fullname', 'application_date', 'faculty', 'department')
[15513]45
[16690]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
[15513]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',
[15514]80            'display_fullname') and context is not None:
[15513]81            applicant = context.__parent__
82            value = getattr(applicant, name, None)
[15514]83        if name in ('course1', 'course2') and context is not None:
84            applicant = context.__parent__
[15516]85            value = getattr(getattr(applicant, name, None), 'code', None)
[15513]86        return super(
87            CustomApplicantPaymentExporter, self).mangle_value(
88            value, name, context=context)
Note: See TracBrowser for help on using the repository browser.