[7696] | 1 | ## $Id: utils.py 14691 2017-06-14 05:20:25Z 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 | |
---|
[13816] | 21 | import grok |
---|
| 22 | from time import time |
---|
[8821] | 23 | from kofacustom.nigeria.applicants.utils import NigeriaApplicantsUtils |
---|
[8647] | 24 | from waeup.kofa.applicants.workflow import (INITIALIZED, |
---|
| 25 | STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED) |
---|
[13816] | 26 | from waeup.uniben.applicants.interfaces import REGISTRATION_CATS |
---|
[8051] | 27 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7696] | 28 | |
---|
[11782] | 29 | class CustomApplicantsUtils(NigeriaApplicantsUtils): |
---|
[7696] | 30 | """A collection of parameters and methods subject to customization. |
---|
| 31 | """ |
---|
| 32 | |
---|
[9635] | 33 | APP_TYPES_DICT = { |
---|
| 34 | 'pude': ['Post-UDE Screening', 'PUDE'], |
---|
| 35 | 'sandwich': ['Part-Time Degree in Education', 'SAND'], |
---|
| 36 | 'pt': ['Part-Time Degree Programmes', 'PTP'], |
---|
[11827] | 37 | 'ptext': ['Part-Time Degree Programmes (extended application)', 'PTP'], |
---|
[9635] | 38 | 'putme': ['Post-UTME Screening Exercise', 'PUTME'], |
---|
| 39 | 'app': ['General Studies', 'APP'], |
---|
| 40 | 'cest': ['Common Entry Screening Test', 'CEST'], |
---|
| 41 | 'ct': ['Certificate Programmes', 'CTP'], |
---|
| 42 | 'dp': ['Diploma Programmes', 'DPP'], |
---|
| 43 | 'dpft': ['Diploma Full-Time Programmes', 'DPP'], |
---|
[13011] | 44 | 'pg': ['Postgraduate Programmes (main advert)', 'PG'], |
---|
| 45 | 'pga': ['Postgraduate Programmes (1st supplementary advert)', 'PG'], |
---|
| 46 | 'pgb': ['Postgraduate Programmes (2nd supplementary advert)', 'PG'], |
---|
| 47 | 'pgc': ['Postgraduate Programmes (3rd supplementary advert)', 'PG'], |
---|
[13245] | 48 | 'pgd': ['Postgraduate Programmes (4th supplementary advert)', 'PG'], |
---|
[13615] | 49 | 'pgn': ['NILS Postgraduate Programmes', 'PG'], |
---|
[14691] | 50 | 'pre': ['JUPEB Pre-Degree (Foundation) Studies', 'PRE'], |
---|
[13151] | 51 | 'cbt': ['UNIBEN CBT Practice Test', 'CBT'], |
---|
[14061] | 52 | 'ab': ['Asaba Programmes', 'ASA'], |
---|
| 53 | 'ak': ['Akoka Programmes', 'AKO'], |
---|
| 54 | 'akj': ['Akoka JUPEB', 'AKO'], |
---|
[13796] | 55 | 'ictwk': ['ICT Week Registration', 'ICT'], |
---|
[13947] | 56 | 'ase': ['Uniben Admission Screening Exercise', 'ASE'], |
---|
[14162] | 57 | 'asea': ['Uniben Admission Screening Exercise ' |
---|
| 58 | '(1st supplementary advert)', 'ASE'], |
---|
| 59 | 'aseb': ['Uniben Admission Screening Exercise ' |
---|
| 60 | '(2nd supplementary advert)', 'ASE'], |
---|
[9635] | 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
[8647] | 64 | # Temporarily disabled |
---|
| 65 | def xxx_getApplicantsStatistics(self, container): |
---|
| 66 | state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0, |
---|
| 67 | ADMITTED:0, NOT_ADMITTED:0, CREATED:0} |
---|
| 68 | faculty_keys = grok.getSite()['faculties'].keys() |
---|
| 69 | fac_stats = dict([(i,0) for i in faculty_keys]) |
---|
| 70 | for key in container.keys(): |
---|
| 71 | state = container[key].state |
---|
| 72 | state_stats[state] += 1 |
---|
| 73 | cert = getattr(container[key],'course1',None) |
---|
| 74 | if cert is not None and state == SUBMITTED: |
---|
| 75 | faculty = cert.__parent__.__parent__.__parent__ |
---|
| 76 | fac_stats[faculty.__name__] += 1 |
---|
| 77 | return state_stats, fac_stats |
---|
[13815] | 78 | |
---|
| 79 | |
---|
| 80 | def setPaymentDetails(self, container, payment, applicant): |
---|
| 81 | """Set the payment data of an applicant. |
---|
| 82 | In contrast to its `StudentsUtils` counterpart, the payment ticket |
---|
| 83 | must exist and is an argument of this method. |
---|
| 84 | """ |
---|
| 85 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 86 | session = str(container.year) |
---|
| 87 | try: |
---|
| 88 | session_config = grok.getSite()['configuration'][session] |
---|
| 89 | except KeyError: |
---|
| 90 | return _(u'Session configuration object is not available.') |
---|
| 91 | payment.p_id = "p%s" % timestamp |
---|
| 92 | payment.p_item = container.title |
---|
| 93 | payment.p_session = container.year |
---|
| 94 | payment.amount_auth = 0.0 |
---|
| 95 | if applicant.special: |
---|
| 96 | if applicant.special_application: |
---|
| 97 | fee_name = applicant.special_application + '_fee' |
---|
| 98 | payment.amount_auth = getattr(session_config, fee_name, None) |
---|
| 99 | payment.p_category = applicant.special_application |
---|
| 100 | return |
---|
[13816] | 101 | elif applicant.__parent__.prefix == 'ictwk': |
---|
| 102 | payment.p_category = 'registration' |
---|
| 103 | for cat in applicant.registration_cats: |
---|
| 104 | payment.amount_auth += REGISTRATION_CATS[cat][1] |
---|
| 105 | else: |
---|
| 106 | payment.p_category = 'application' |
---|
| 107 | container_fee = container.application_fee |
---|
[13887] | 108 | if not container_fee: |
---|
| 109 | return _('Amount could not be determined.') |
---|
| 110 | payment.amount_auth = container_fee |
---|
[13815] | 111 | return |
---|