bgneal@609: """ bgneal@609: This module contains country flag data & functions. bgneal@609: bgneal@609: """ bgneal@609: from __future__ import with_statement bgneal@609: import os.path bgneal@609: import locale bgneal@609: import logging bgneal@609: bgneal@609: import django.utils.simplejson as json bgneal@609: bgneal@609: bgneal@609: # Read flag data from external JSON file: bgneal@609: bgneal@609: FLAG_DATA = {} bgneal@609: bgneal@609: datafile = os.path.join(os.path.split(__file__)[0], 'flag_data.json') bgneal@609: bgneal@609: try: bgneal@609: with open(datafile, 'r') as fp: bgneal@609: FLAG_DATA = json.load(fp, encoding='utf-8') bgneal@609: except IOError: bgneal@609: FLAG_DATA = {} bgneal@609: logging.error("Could not load flag_data.json") bgneal@609: bgneal@609: # Build a choices list for use with Django models, etc. bgneal@609: # The locale is set in order to sort the place names correctly: bgneal@609: bgneal@609: locale.setlocale(locale.LC_ALL, '') bgneal@609: bgneal@609: FLAG_CHOICES = sorted(FLAG_DATA.items(), bgneal@609: cmp=lambda lhs, rhs: locale.strcoll(lhs[1], rhs[1]))