[7696] | 1 | ## $Id: utils.py 17366 2023-03-27 21:26:16Z 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 |
---|
[16245] | 23 | from datetime import datetime |
---|
[8821] | 24 | from kofacustom.nigeria.applicants.utils import NigeriaApplicantsUtils |
---|
[8647] | 25 | from waeup.kofa.applicants.workflow import (INITIALIZED, |
---|
| 26 | STARTED, PAID, ADMITTED, NOT_ADMITTED, SUBMITTED, CREATED) |
---|
[16131] | 27 | from waeup.uniben.applicants.interfaces import REGISTRATION_CATS, DESTINATION_COST |
---|
[8051] | 28 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7696] | 29 | |
---|
[11782] | 30 | class CustomApplicantsUtils(NigeriaApplicantsUtils): |
---|
[7696] | 31 | """A collection of parameters and methods subject to customization. |
---|
| 32 | """ |
---|
| 33 | |
---|
[16164] | 34 | ADDITIONAL_FILES = ( |
---|
[16547] | 35 | ('Eligibility Form','eligibility'), |
---|
| 36 | ('Statement of Result','res_stat'), |
---|
[16164] | 37 | ) |
---|
| 38 | |
---|
[9635] | 39 | APP_TYPES_DICT = { |
---|
| 40 | 'pude': ['Post-UDE Screening', 'PUDE'], |
---|
| 41 | 'sandwich': ['Part-Time Degree in Education', 'SAND'], |
---|
| 42 | 'pt': ['Part-Time Degree Programmes', 'PTP'], |
---|
[11827] | 43 | 'ptext': ['Part-Time Degree Programmes (extended application)', 'PTP'], |
---|
[9635] | 44 | 'putme': ['Post-UTME Screening Exercise', 'PUTME'], |
---|
| 45 | 'app': ['General Studies', 'APP'], |
---|
| 46 | 'cest': ['Common Entry Screening Test', 'CEST'], |
---|
| 47 | 'ct': ['Certificate Programmes', 'CTP'], |
---|
| 48 | 'dp': ['Diploma Programmes', 'DPP'], |
---|
| 49 | 'dpft': ['Diploma Full-Time Programmes', 'DPP'], |
---|
[13011] | 50 | 'pg': ['Postgraduate Programmes (main advert)', 'PG'], |
---|
[17048] | 51 | 'pgcoe': ['CoE Programmes', 'PG'], |
---|
[13615] | 52 | 'pgn': ['NILS Postgraduate Programmes', 'PG'], |
---|
[14691] | 53 | 'pre': ['JUPEB Pre-Degree (Foundation) Studies', 'PRE'], |
---|
[13151] | 54 | 'cbt': ['UNIBEN CBT Practice Test', 'CBT'], |
---|
[14061] | 55 | 'ab': ['Asaba Programmes', 'ASA'], |
---|
| 56 | 'ak': ['Akoka Programmes', 'AKO'], |
---|
| 57 | 'akj': ['Akoka JUPEB', 'AKO'], |
---|
[13796] | 58 | 'ictwk': ['ICT Week Registration', 'ICT'], |
---|
[13947] | 59 | 'ase': ['Uniben Admission Screening Exercise', 'ASE'], |
---|
[14162] | 60 | 'asea': ['Uniben Admission Screening Exercise ' |
---|
| 61 | '(1st supplementary advert)', 'ASE'], |
---|
| 62 | 'aseb': ['Uniben Admission Screening Exercise ' |
---|
| 63 | '(2nd supplementary advert)', 'ASE'], |
---|
[14811] | 64 | 'spft': ['Special Full-Time Programmes', 'SP'], |
---|
[16175] | 65 | 'tscf': ['Transcript (without student record)', 'TRF'], |
---|
| 66 | 'tscs': ['Transcript (with student record)', 'TRS'], |
---|
[16807] | 67 | 'flc': ['French Language Centre', 'FR'], |
---|
[17140] | 68 | 'cdl': ['Centre For Distance Learning Programmes', 'CDL'], |
---|
[9635] | 69 | } |
---|
| 70 | |
---|
[17048] | 71 | |
---|
[14867] | 72 | SEPARATORS_DICT = { |
---|
| 73 | 'form.applicant_id': _(u'Base Data'), |
---|
| 74 | 'form.course1': _(u'Programmes/Courses Desired'), |
---|
| 75 | 'form.hq_type': _(u'Higher Education Record'), |
---|
| 76 | 'form.presently': _(u'Course or Programme Presently Attending'), |
---|
| 77 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 78 | 'form.employer': _(u'Employment History'), |
---|
| 79 | 'form.jamb_subjects': _(u'JAMB Data'), |
---|
| 80 | 'form.jamb_subjects_list': _(u'JAMB Data'), |
---|
| 81 | 'form.notice': _(u'Application Process Information'), |
---|
| 82 | 'form.pp_school': _(u'Post Primary School Qualification'), |
---|
| 83 | 'form.presently_inst': _(u'Presently attending a course or programme'), |
---|
| 84 | 'form.fst_sit_fname': _(u'Ordinary Level First Sitting Record'), |
---|
| 85 | 'form.scd_sit_fname': _(u'Ordinary Level Second Sitting Record'), |
---|
| 86 | 'form.referees': _(u'Referees'), |
---|
| 87 | } |
---|
[9635] | 88 | |
---|
[14867] | 89 | |
---|
[8647] | 90 | # Temporarily disabled |
---|
| 91 | def xxx_getApplicantsStatistics(self, container): |
---|
| 92 | state_stats = {INITIALIZED:0, STARTED:0, PAID:0, SUBMITTED:0, |
---|
| 93 | ADMITTED:0, NOT_ADMITTED:0, CREATED:0} |
---|
| 94 | faculty_keys = grok.getSite()['faculties'].keys() |
---|
| 95 | fac_stats = dict([(i,0) for i in faculty_keys]) |
---|
| 96 | for key in container.keys(): |
---|
| 97 | state = container[key].state |
---|
| 98 | state_stats[state] += 1 |
---|
| 99 | cert = getattr(container[key],'course1',None) |
---|
| 100 | if cert is not None and state == SUBMITTED: |
---|
| 101 | faculty = cert.__parent__.__parent__.__parent__ |
---|
| 102 | fac_stats[faculty.__name__] += 1 |
---|
| 103 | return state_stats, fac_stats |
---|
[13815] | 104 | |
---|
| 105 | |
---|
| 106 | def setPaymentDetails(self, container, payment, applicant): |
---|
| 107 | """Set the payment data of an applicant. |
---|
| 108 | In contrast to its `StudentsUtils` counterpart, the payment ticket |
---|
| 109 | must exist and is an argument of this method. |
---|
| 110 | """ |
---|
| 111 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[16245] | 112 | if container.year: |
---|
| 113 | session = str(container.year) |
---|
| 114 | try: |
---|
| 115 | session_config = grok.getSite()['configuration'][session] |
---|
| 116 | except KeyError: |
---|
| 117 | return _(u'Session configuration object is not available.') |
---|
[13815] | 118 | payment.p_id = "p%s" % timestamp |
---|
| 119 | payment.p_item = container.title |
---|
[16245] | 120 | if container.year: |
---|
| 121 | payment.p_session = container.year |
---|
| 122 | else: |
---|
| 123 | payment.p_session = datetime.now().year |
---|
[13815] | 124 | payment.amount_auth = 0.0 |
---|
| 125 | if applicant.special: |
---|
| 126 | if applicant.special_application: |
---|
| 127 | fee_name = applicant.special_application + '_fee' |
---|
| 128 | payment.amount_auth = getattr(session_config, fee_name, None) |
---|
| 129 | payment.p_category = applicant.special_application |
---|
| 130 | return |
---|
[13816] | 131 | elif applicant.__parent__.prefix == 'ictwk': |
---|
| 132 | payment.p_category = 'registration' |
---|
| 133 | for cat in applicant.registration_cats: |
---|
| 134 | payment.amount_auth += REGISTRATION_CATS[cat][1] |
---|
[16144] | 135 | return |
---|
[16173] | 136 | elif applicant.container_code.startswith('tsc'): |
---|
[16216] | 137 | if not applicant.charge: |
---|
| 138 | return _(u'No transcript charge selected.') |
---|
[16131] | 139 | cost = DESTINATION_COST[applicant.charge][1] |
---|
| 140 | payment.amount_auth = applicant.no_copies * cost |
---|
[16226] | 141 | payment.p_category = 'transcript' |
---|
[16144] | 142 | return |
---|
[13816] | 143 | else: |
---|
| 144 | payment.p_category = 'application' |
---|
| 145 | container_fee = container.application_fee |
---|
[13887] | 146 | if not container_fee: |
---|
| 147 | return _('Amount could not be determined.') |
---|
| 148 | payment.amount_auth = container_fee |
---|
[13815] | 149 | return |
---|
[16199] | 150 | |
---|
| 151 | def isPictureEditable(self, container): |
---|
| 152 | """False if applicants are not allowed to edit uploaded pictures. |
---|
| 153 | """ |
---|
| 154 | if container.code.startswith('ase'): |
---|
| 155 | return False |
---|
[16314] | 156 | if container.code.startswith('pude'): |
---|
| 157 | return False |
---|
[16199] | 158 | return container.with_picture |
---|
[17366] | 159 | |
---|
| 160 | def sortCertificates(self, context, resultset): |
---|
| 161 | """Sort already filtered certificates in `AppCatCertificateSource`. |
---|
| 162 | """ |
---|
| 163 | resultlist = sorted(resultset, key=lambda |
---|
| 164 | value: value.__parent__.__parent__.__parent__.code + |
---|
| 165 | value.__parent__.__parent__.code + |
---|
| 166 | value.code) |
---|
| 167 | curr_course = context.course1 |
---|
| 168 | if curr_course is not None and curr_course not in resultlist: |
---|
| 169 | resultlist = [curr_course,] + resultlist |
---|
| 170 | return resultlist |
---|
| 171 | |
---|
| 172 | def getCertTitle(self, context, value): |
---|
| 173 | """Compose the titles in `AppCatCertificateSource`. |
---|
| 174 | """ |
---|
| 175 | try: title = "%s / %s / %s (%s)" % ( |
---|
| 176 | value.__parent__.__parent__.__parent__.title, |
---|
| 177 | value.__parent__.__parent__.title, |
---|
| 178 | value.title, value.code) |
---|
| 179 | except AttributeError: |
---|
| 180 | title = "NA / %s (%s)" % (value.title, value.code) |
---|
| 181 | return title |
---|