source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/applicants/applicant.py @ 15429

Last change on this file since 15429 was 15218, checked in by Henrik Bettermann, 6 years ago

Implement special application (for supplementary payments).

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1## $Id: applicant.py 15218 2018-11-08 12:45:03Z henrik $
2##
3## Copyright (C) 2011 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
19import grok
20from zope.interface import implementedBy
21from waeup.kofa.applicants.applicant import ApplicantFactory
22from waeup.kofa.utils.helpers import attrs_to_fields
23from waeup.kofa.interfaces import IObjectHistory
24from waeup.kofa.applicants.workflow import (
25    application_states_dict, ADMITTED, NOT_ADMITTED, CREATED)
26from kofacustom.nigeria.applicants.applicant import NigeriaApplicant
27from kofacustom.edopoly.applicants.interfaces import(
28    ICustomApplicant, ICustomUGApplicantEdit, ICustomPGApplicantEdit,
29    IPUTMEApplicantEdit, ICustomSpecialApplicant)
30
31class CustomApplicant(NigeriaApplicant):
32
33    grok.implements(ICustomApplicant, ICustomUGApplicantEdit,
34        ICustomPGApplicantEdit, IPUTMEApplicantEdit, ICustomSpecialApplicant)
35    grok.provides(ICustomApplicant)
36
37    def admchecking_fee_paid(self):
38        # We don't charge if admission checking fee is not set.
39        session = str(self.__parent__.year)
40        try:
41            session_config = grok.getSite()['configuration'][session]
42        except KeyError:
43            return True
44        if session_config.admchecking_fee == 0:
45            return True
46        for key in self.keys():
47            ticket = self[key]
48            if ticket.p_state == 'paid' and \
49                ticket.p_category == 'admission_checking':
50                return True
51        return False
52
53    @property
54    def history(self):
55        # We do not provide a history
56        if self.state in (ADMITTED, NOT_ADMITTED, CREATED) \
57            and not self.admchecking_fee_paid():
58            return
59        history = IObjectHistory(self)
60        return history
61
62    @property
63    def translated_state(self):
64        if self.state in (ADMITTED, NOT_ADMITTED, CREATED) \
65            and not self.admchecking_fee_paid():
66            return
67        try:
68            state = application_states_dict[self.state]
69        except LookupError:  # in unit tests
70            return
71        return state
72
73# Set all attributes of CustomApplicant required in ICustomApplicant as field
74# properties. Doing this, we do not have to set initial attributes
75# ourselves and as a bonus we get free validation when an attribute is
76# set.
77CustomApplicant = attrs_to_fields(CustomApplicant)
78
79class CustomApplicantFactory(ApplicantFactory):
80    """A factory for customized applicants.
81    """
82
83    def __call__(self, *args, **kw):
84        return CustomApplicant()
85
86    def getInterfaces(self):
87        return implementedBy(CustomApplicant)
Note: See TracBrowser for help on using the repository browser.