comparison bio/flags.py @ 609:678a1a2ef55a

For issue 16, add country flag icons to user profiles & forum posts.
author Brian Neal <bgneal@gmail.com>
date Sat, 28 Jul 2012 15:12:09 -0500
parents
children 89b240fe9297
comparison
equal deleted inserted replaced
608:8ddd6490cbc9 609:678a1a2ef55a
1 """
2 This module contains country flag data & functions.
3
4 """
5 from __future__ import with_statement
6 import os.path
7 import locale
8 import logging
9
10 import django.utils.simplejson as json
11
12
13 # Read flag data from external JSON file:
14
15 FLAG_DATA = {}
16
17 datafile = os.path.join(os.path.split(__file__)[0], 'flag_data.json')
18
19 try:
20 with open(datafile, 'r') as fp:
21 FLAG_DATA = json.load(fp, encoding='utf-8')
22 except IOError:
23 FLAG_DATA = {}
24 logging.error("Could not load flag_data.json")
25
26 # Build a choices list for use with Django models, etc.
27 # The locale is set in order to sort the place names correctly:
28
29 locale.setlocale(locale.LC_ALL, '')
30
31 FLAG_CHOICES = sorted(FLAG_DATA.items(),
32 cmp=lambda lhs, rhs: locale.strcoll(lhs[1], rhs[1]))