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

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

Hide workflow state and history if admission checking fee has not been paid.

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