source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/utils.py @ 16134

Last change on this file since 16134 was 16134, checked in by Henrik Bettermann, 4 years ago

Ease customization.

  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1## $Id: utils.py 16134 2020-06-28 18:01:52Z 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"""General helper functions and utilities for the applicants section.
19"""
20
21from time import time
22import grok
23from zope.component import getUtility
24from zope.catalog.interfaces import ICatalog
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.applicants.interfaces import IApplicantsUtils
27from waeup.kofa.applicants.workflow import (INITIALIZED,
28    STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED, PROCESSED)
29
30class ApplicantsUtils(grok.GlobalUtility):
31    """A collection of parameters and methods subject to customization.
32    """
33    grok.implements(IApplicantsUtils)
34
35    #: A dictionary containing application type names, titles and
36    #: access code prefixes (meanwhile deprecated).
37    APP_TYPES_DICT = {
38      'app': ['General Studies', 'APP'],
39      'special': ['Special Application', 'SPE'],
40      }
41
42    #: A dictionary which maps widget names to headlines.
43    #: The headline is rendered in forms and on pdf slips above the
44    #: respective display or input widget.
45    SEPARATORS_DICT = {
46      'form.applicant_id': _(u'Base Data'),
47      'form.course1': _(u'Desired Study Courses'),
48      'form.notice': _(u'Application Process Data'),
49      'form.referees': _(u'Referees (automatically invited by email '
50                          'after final submission of this form)'),
51      }
52
53    #: A tuple of tuple of file names to be uploaded by applicants and copied
54    #: over to the students section.
55    ADDITIONAL_FILES = (('Test File','testfile.pdf'),)
56
57    def setPaymentDetails(self, container, payment, applicant):
58        """Set the payment data of an applicant.
59        In contrast to its `StudentsUtils` counterpart, the payment ticket
60        must exist and is an argument of this method.
61        """
62        timestamp = ("%d" % int(time()*10000))[1:]
63        session = str(container.year)
64        try:
65            session_config = grok.getSite()['configuration'][session]
66        except KeyError:
67            return _(u'Session configuration object is not available.')
68        payment.p_id = "p%s" % timestamp
69        payment.p_item = container.title
70        payment.p_session = container.year
71        payment.amount_auth = 0.0
72        if applicant.special:
73            if applicant.special_application:
74                fee_name = applicant.special_application + '_fee'
75                payment.amount_auth = getattr(session_config, fee_name, None)
76                if payment.amount_auth in (0.0, None):
77                    return _('Amount could not be determined.')
78                payment.p_category = applicant.special_application
79            return
80        payment.p_category = 'application'
81        container_fee = container.application_fee
82        if not container_fee:
83            return _('Amount could not be determined.')
84        payment.amount_auth = container_fee
85        return
86
87    def getApplicantsStatistics(self, container):
88        """Count applicants in applicants containers.
89        """
90        state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0,
91            ADMITTED:0, NOT_ADMITTED:0, CREATED:0, PROCESSED:0}
92        cat = getUtility(ICatalog, name='applicants_catalog')
93        code = container.code
94        for state in state_stats:
95            if state == 'initialized':
96                results = cat.searchResults(
97                                state=(state, state),
98                                container_code=(code + '+', code + '+'))
99                state_stats[state] = len(results)
100            else:
101                results = cat.searchResults(
102                    state=(state, state),
103                    container_code=(code + '+', code + '-'))
104                state_stats[state] = len(results)
105        return state_stats, None
106
107    def sortCertificates(self, context, resultset):
108        """Sort already filtered certificates in `AppCatCertificateSource`.
109        Display also current course even if certificate in the academic
110        section has been removed.
111        """
112        resultlist = sorted(resultset, key=lambda value: value.code)
113        curr_course = context.course1
114        if curr_course is not None and curr_course not in resultlist:
115            resultlist = [curr_course,] + resultlist
116        return resultlist
117
118    def getCertTitle(self, context, value):
119        """Compose the titles in `AppCatCertificateSource`.
120        """
121        return "%s - %s" % (value.code, value.title)
122
123    def isPictureEditable(self, container):
124        """False if applicants are not allowed to edit uploaded pictures.
125        """
126        return container.with_picture
Note: See TracBrowser for help on using the repository browser.