utils.utils - Utilities

General helper utilities for Kofa.

waeup.kofa.utils.utils.INT_PHONE_PREFIXES = [(99, u'Germany', '49'), (1, u'Nigeria', '234'), (99, u'U.S.', '1')]

A list of phone prefixes (order num, country, prefix). Items with same order num will be sorted alphabetically. The lower the order num, the higher the precedence.

class waeup.kofa.utils.utils.KofaUtils[source]

Bases: grokcore.component.components.GlobalUtility

A collection of parameters and methods subject to customization.

APP_CATS_DICT = {'cest': 'Part-Time, Diploma, Certificate', 'no': 'no application', 'pg': 'Postgraduate', 'sandwich': 'Sandwich', 'basic': 'Basic Application'}
BALANCE_PAYMENT_CATEGORIES = {'schoolfee': 'School Fee'}
COURSE_CATEGORY_DICT = {}
DEGREES_DICT = {'BAGR': 'Bachelor of Agriculture', 'MD': 'Doctor of Medicine', 'MA': 'Master of Arts', 'BA': 'Bachelor of Arts', 'MUSM': 'Master of Music', 'DBA': 'Doctor of Business Administration', 'LLB': 'Bachelor of Laws', 'PHD': 'Doctor of Philosophy', 'MBA': 'Master of Business Administration', 'LLM': 'Master of Laws'}
DISABLE_PAYMENT_GROUP_DICT = {'sf_all': 'School Fee - All Students'}
EXAM_GRADES = (('A', 'Best'), ('B', 'Better'), ('C', 'Good'))

Exam grades. The tuple is sorted as it should be displayed in select boxes.

EXAM_SUBJECTS_DICT = {'computer_science': 'Computer Science', 'math': 'Mathematics'}
INST_TYPES_DICT = {'institute': 'Institute of', 'none': '', 'directorate': 'Directorate of', 'college': 'College of', 'office': 'Office for', 'faculty': 'Faculty of', 'department': 'Department of', 'centre': 'Centre for', 'school': 'School of', 'school_for': 'School for'}
MODE_GROUPS = {'Postgraduate Full-Time': ('pg_ft',), 'Postgraduate Part-Time': ('pg_pt',), 'All': ('all',), 'Undergraduate Full-Time': ('ug_ft',), 'Undergraduate Part-Time': ('ug_pt',)}
PAYMENT_CATEGORIES = {'gown': 'Gown Hire Fee', 'hostel_maintenance': 'Hostel Maintenance Fee', 'transcript': 'Transcript Fee', 'late_registration': 'Late Course Registration Fee', 'application': 'Application Fee', 'transfer': 'Transfer Fee', 'clearance': 'Acceptance Fee', 'bed_allocation': 'Bed Allocation Fee', 'schoolfee': 'School Fee'}
PORTAL_LANGUAGE = 'en'

This the only place where we define the portal language which is used for the translation of system messages (e.g. object histories) pdf slips.

PREFERRED_LANGUAGES_DICT = {'fr': (2, u'Français'), 'en': (1, u'English'), 'yo': (5, u'Yoruba'), 'de': (3, u'Deutsch'), 'ha': (4, u'Hausa'), 'ig': (6, u'Igbo')}
PREVIOUS_PAYMENT_CATEGORIES = {'gown': 'Gown Hire Fee', 'transfer': 'Transfer Fee', 'application': 'Application Fee', 'hostel_maintenance': 'Hostel Maintenance Fee', 'late_registration': 'Late Course Registration Fee', 'clearance': 'Acceptance Fee', 'transcript': 'Transcript Fee', 'schoolfee': 'School Fee', 'bed_allocation': 'Bed Allocation Fee'}
REPORTABLE_PAYMENT_CATEGORIES = {'hostel_maintenance': 'Hostel Maintenance Fee', 'clearance': 'Acceptance Fee', 'schoolfee': 'School Fee', 'gown': 'Gown Hire Fee'}
SELECTABLE_PAYMENT_CATEGORIES = {'gown': 'Gown Hire Fee', 'transfer': 'Transfer Fee', 'application': 'Application Fee', 'hostel_maintenance': 'Hostel Maintenance Fee', 'late_registration': 'Late Course Registration Fee', 'clearance': 'Acceptance Fee', 'transcript': 'Transcript Fee', 'schoolfee': 'School Fee', 'bed_allocation': 'Bed Allocation Fee'}
SEMESTER_DICT = {1: '1st Semester', 2: '2nd Semester', 3: 'Combined', 9: 'N/A'}
SPECIAL_APP_DICT = {'clearance': 'Acceptance Fee', 'transcript': 'Transcript Fee Payment'}
SPECIAL_HANDLING_DICT = {'regular': 'Regular Hostel', 'pg': 'Postgraduate Hostel', 'blocked': 'Blocked Hostel'}
STUDY_MODES_DICT = {'ug_ft': 'Undergraduate Full-Time', 'transfer': 'Transfer', 'pg_pt': 'Postgraduate Part-Time', 'ug_pt': 'Undergraduate Part-Time', 'pg_ft': 'Postgraduate Full-Time'}
SYSTEM_MAX_LOAD = {'virt-mem': None, 'cpu-load': 100.0, 'swap-mem': None}

Set positive number for allowed max, negative for required min avail. Use integer for bytes value, float for percent value. cpu-load, of course, accepts float values only. swap-mem = Swap Memory, virt-mem = Virtual Memory, cpu-load = CPU load in percent.

VERDICTS_DICT = {'A': 'Successful student', '0': u'(not yet)', 'C': 'Student on probation', 'B': 'Student with carryover courses'}
__doc__ = 'A collection of parameters and methods subject to customization.\n '
__implemented__ = <implementedBy waeup.kofa.utils.utils.KofaUtils>
__module__ = 'waeup.kofa.utils.utils'
__provides__

Special descriptor for class __provides__

The descriptor caches the implementedBy info, so that we can get declarations for objects without instance-specific interfaces a bit quicker.

For example:

>>> from zope.interface import Interface
>>> class IFooFactory(Interface):
...     pass
>>> class IFoo(Interface):
...     pass
>>> class C(object):
...     implements(IFoo)
...     classProvides(IFooFactory)
>>> [i.getName() for i in C.__provides__]
['IFooFactory']
>>> [i.getName() for i in C().__provides__]
['IFoo']
expensive_actions_allowed(type=None, request=None)[source]

Tell, whether expensive actions are currently allowed. Check system load/health (or other external circumstances) and locally set values to see, whether expensive actions should be allowed (True) or better avoided (False). Use this to allow or forbid exports, report generations, or similar actions.

export_disabled_message()[source]
format_float(value, prec)[source]
fullname(firstname, lastname, middlename=None)[source]

Construct fullname.

genPassword(length=8, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')[source]

Generate a random password.

getPaymentItem(payment)[source]

Return payment item. This method can be used to customize the display_item property attribute, e.g. in order to hide bed coordinates if maintenance fee is not paid.

inviteReferee(referee, applicant, url_info=None)[source]

Send invitation email to referee.

sendContactForm(from_name, from_addr, rcpt_name, rcpt_addr, from_username, usertype, portal, body, subject)[source]

Send an email with data provided by forms.

sendCredentials(user, password=None, url_info=None, msg=None)[source]

Send credentials as email. Input is the user for which credentials are sent and the password. Method returns True or False to indicate successful operation.

classmethod sorted_phone_prefixes(data=[(99, u'Germany', '49'), (1, u'Nigeria', '234'), (99, u'U.S.', '1')], request=None)[source]
tzinfo

Time zone of the university.

waeup.kofa.utils.utils.send_mail(from_name, from_addr, rcpt_name, rcpt_addr, subject, body, config)[source]

Wrapper for the real SMTP functionality in waeup.kofa.smtp.

Merely here to stay compatible with lots of calls to this place.

waeup.kofa.utils.utils.sorted_phone_prefixes(data=[(99, u'Germany', '49'), (1, u'Nigeria', '234'), (99, u'U.S.', '1')], request=None)[source]

Sorted tuples of phone prefixes.

Ordered as shown above and formatted for use in select boxes.

If request is given, we’ll try to translate all country names in order to sort alphabetically correctly.

XXX: This is a function (and not a constant) as different languages might give different orders. This is not tested yet.

XXX: If we really want to use alphabetic ordering here, we might think about caching results of translations.