view bio/flags.py @ 1184:fbfb1a9c70e2

Make donations business a list. Paypal is now returning a different business email in IPN messages.
author Brian Neal <bgneal@gmail.com>
date Sun, 17 Oct 2021 14:40:53 -0500
parents 89b240fe9297
children
line wrap: on
line source
"""
This module contains country flag data & functions.

"""
import json
import os.path
import locale
import logging


# Read flag data from external JSON file:

FLAG_DATA = {}

datafile = os.path.join(os.path.split(__file__)[0], 'flag_data.json')

try:
    with open(datafile, 'r') as fp:
        FLAG_DATA = json.load(fp, encoding='utf-8')
except IOError:
    FLAG_DATA = {}
    logging.error("Could not load flag_data.json")

# Build a choices list for use with Django models, etc.
# The locale is set in order to sort the place names correctly:

locale.setlocale(locale.LC_ALL, '')

FLAG_CHOICES = sorted(FLAG_DATA.items(),
        cmp=lambda lhs, rhs: locale.strcoll(lhs[1], rhs[1]))