[7682] | 1 | ## $Id: utils.py 10186 2013-05-22 07:34:47Z 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 application section. |
---|
| 19 | """ |
---|
| 20 | |
---|
[8524] | 21 | from time import time |
---|
[7682] | 22 | import grok |
---|
[8645] | 23 | from zope.component import getUtility |
---|
| 24 | from zope.catalog.interfaces import ICatalog |
---|
| 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7811] | 26 | from waeup.kofa.applicants.interfaces import IApplicantsUtils |
---|
[8645] | 27 | from waeup.kofa.applicants.workflow import (INITIALIZED, |
---|
| 28 | STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED) |
---|
[7682] | 29 | |
---|
| 30 | class 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'], |
---|
| 37 | } |
---|
[8046] | 38 | |
---|
| 39 | SEPARATORS_DICT = { |
---|
| 40 | 'form.course1': _(u'Desired Study Courses'), |
---|
[9047] | 41 | 'form.student_id': _(u'Process Data'), |
---|
[8046] | 42 | } |
---|
[8524] | 43 | |
---|
| 44 | def setPaymentDetails(self, container, payment): |
---|
| 45 | """Set the payment data of an applicant. |
---|
| 46 | """ |
---|
[8884] | 47 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8534] | 48 | container_fee = container.application_fee |
---|
| 49 | if container_fee: |
---|
| 50 | payment.amount_auth = container_fee |
---|
| 51 | else: |
---|
| 52 | session = str(container.year) |
---|
| 53 | try: |
---|
| 54 | session_config = grok.getSite()['configuration'][session] |
---|
| 55 | except KeyError: |
---|
| 56 | return _(u'Session configuration object is not available.') |
---|
| 57 | payment.amount_auth = session_config.application_fee |
---|
[8524] | 58 | payment.p_id = "p%s" % timestamp |
---|
| 59 | payment.p_item = container.title |
---|
| 60 | payment.p_session = container.year |
---|
| 61 | payment.p_category = 'application' |
---|
| 62 | return None |
---|
[8645] | 63 | |
---|
[8664] | 64 | def getApplicantsStatistics(self, container): |
---|
[10184] | 65 | """Count applicants in containers. |
---|
| 66 | """ |
---|
[8645] | 67 | state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0, |
---|
| 68 | ADMITTED:0, NOT_ADMITTED:0, CREATED:0} |
---|
| 69 | cat = getUtility(ICatalog, name='applicants_catalog') |
---|
| 70 | code = container.code |
---|
| 71 | year = int(code[-4:]) |
---|
| 72 | target = code[:-4] |
---|
| 73 | mxcode = target + str(year + 1) |
---|
| 74 | for state in state_stats: |
---|
| 75 | state_stats[state] = len(cat.searchResults( |
---|
| 76 | state=(state, state), |
---|
| 77 | applicant_id=(code, mxcode))) |
---|
| 78 | return state_stats, None |
---|
[10184] | 79 | |
---|
| 80 | def filterCertificates(self, resultset): |
---|
[10186] | 81 | """Filter and sort certificates in AppCatCertificateSource. |
---|
[10184] | 82 | """ |
---|
| 83 | return sorted(resultset, key=lambda value: value.code) |
---|
[10186] | 84 | |
---|
| 85 | def getCertTitle(self, context, value): |
---|
| 86 | """Compose the titles in AppCatCertificateSource. |
---|
| 87 | """ |
---|
| 88 | return "%s - %s" % (value.code, value.title) |
---|