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

Last change on this file since 16045 was 15946, checked in by Henrik Bettermann, 5 years ago

Make further adjustments for fileupload in the applicants section.

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