[10765] | 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 | |
---|
| 19 | import grok |
---|
| 20 | from zope.interface import implementedBy |
---|
| 21 | from waeup.kofa.applicants.applicant import ApplicantFactory |
---|
| 22 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[15131] | 23 | from waeup.kofa.interfaces import IObjectHistory |
---|
| 24 | from waeup.kofa.applicants.workflow import ( |
---|
| 25 | application_states_dict, ADMITTED, NOT_ADMITTED, CREATED) |
---|
[10765] | 26 | from kofacustom.nigeria.applicants.applicant import NigeriaApplicant |
---|
[15000] | 27 | from kofacustom.edopoly.applicants.interfaces import( |
---|
[15218] | 28 | ICustomApplicant, ICustomUGApplicantEdit, ICustomPGApplicantEdit, |
---|
| 29 | IPUTMEApplicantEdit, ICustomSpecialApplicant) |
---|
[10765] | 30 | |
---|
| 31 | class CustomApplicant(NigeriaApplicant): |
---|
| 32 | |
---|
| 33 | grok.implements(ICustomApplicant, ICustomUGApplicantEdit, |
---|
[15218] | 34 | ICustomPGApplicantEdit, IPUTMEApplicantEdit, ICustomSpecialApplicant) |
---|
[10765] | 35 | grok.provides(ICustomApplicant) |
---|
| 36 | |
---|
[15123] | 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 | |
---|
[15131] | 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 | |
---|
[10765] | 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. |
---|
| 77 | CustomApplicant = attrs_to_fields(CustomApplicant) |
---|
| 78 | |
---|
| 79 | class 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) |
---|