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

Last change on this file since 11254 was 11254, checked in by uli, 11 years ago

Merge changes from uli-diazo-themed back into trunk. If this works, then a miracle happened.

  • Property svn:keywords set to Id
File size: 4.0 KB
RevLine 
[7682]1## $Id: utils.py 11254 2014-02-22 15:46:03Z uli $
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 application section.
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,
28    STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED)
[7682]29
30class ApplicantsUtils(grok.GlobalUtility):
31    """A collection of parameters and methods subject to customization.
32    """
33    grok.implements(IApplicantsUtils)
34
[7844]35    APP_TYPES_DICT = {
36      'app': ['General Studies', 'APP'],
[10831]37      'special': ['Special Application', 'SPE'],
[7844]38      }
[8046]39
40    SEPARATORS_DICT = {
41      'form.course1': _(u'Desired Study Courses'),
[9047]42      'form.student_id': _(u'Process Data'),
[8046]43      }
[8524]44
[10831]45    def setPaymentDetails(self, container, payment, applicant):
[8524]46        """Set the payment data of an applicant.
47        """
[8884]48        timestamp = ("%d" % int(time()*10000))[1:]
[10832]49        session = str(container.year)
50        try:
51            session_config = grok.getSite()['configuration'][session]
52        except KeyError:
[11254]53            return _(u'Session configuration object is not available.'), None
[10832]54        payment.p_id = "p%s" % timestamp
55        payment.p_item = container.title
56        payment.p_session = container.year
[10841]57        payment.amount_auth = 0.0
[10831]58        if container.prefix.startswith('special'):
[10841]59            if applicant.special_application:
60                fee_name = applicant.special_application + '_fee'
61                payment.amount_auth = getattr(session_config, fee_name, 0.0)
62                payment.p_category = applicant.special_application
[10832]63            return
64        payment.p_category = 'application'
65        container_fee = container.application_fee
66        if container_fee:
67            payment.amount_auth = container_fee
68            return
69        payment.amount_auth = session_config.application_fee
[10843]70        if payment.amount_auth in (0.0, None):
71            return _('Amount could not be determined.'), None
[10832]72        return
[8645]73
[8664]74    def getApplicantsStatistics(self, container):
[10184]75        """Count applicants in containers.
76        """
[8645]77        state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0,
78            ADMITTED:0, NOT_ADMITTED:0, CREATED:0}
79        cat = getUtility(ICatalog, name='applicants_catalog')
80        code = container.code
81        year = int(code[-4:])
82        target = code[:-4]
83        mxcode = target + str(year + 1)
84        for state in state_stats:
85            state_stats[state] = len(cat.searchResults(
86                state=(state, state),
87                applicant_id=(code, mxcode)))
88        return state_stats, None
[10184]89
[10187]90    def filterCertificates(self, context, resultset):
[10186]91        """Filter and sort certificates in AppCatCertificateSource.
[10184]92        """
[10208]93        resultlist = sorted(resultset, key=lambda value: value.code)
94        curr_course = context.course1
95        if curr_course is not None and curr_course not in resultlist:
96            # display also current course even if certificate has been removed
97            resultlist = [curr_course,] + resultlist
98        return resultlist
[10186]99
100    def getCertTitle(self, context, value):
101        """Compose the titles in AppCatCertificateSource.
102        """
103        return "%s - %s" % (value.code, value.title)
Note: See TracBrowser for help on using the repository browser.