from collections import defaultdict
import json
from os.path import abspath, dirname, join
import sys

data_directory = abspath(join(dirname(__file__), '..', 'data'))

print >> sys.stderr, "Loading MapIt data..."

def get_mapit_constituencies(basename):
    with open(join(data_directory, basename)) as f:
        return json.load(f)

def get_constituency_name_map(basename):
    result = {}
    for constituency in get_mapit_constituencies(basename).values():
        result[constituency['name']] = constituency
    return result

class MapItData(object):
    constituencies_2010 = \
        get_mapit_constituencies('mapit-WMC-generation-13.json')
    constituencies_2010_name_map = \
        get_constituency_name_map('mapit-WMC-generation-13.json')

print >> sys.stderr, "Loading party data..."

def get_all_parties():
    result_list = defaultdict(list)
    result_dict = {}
    with open(join(data_directory, 'all-parties-from-popit.json')) as f:
        for party in json.load(f):
            key = party.get('register', '')
            result_list[key].append((party['id'], party['name']))
            result_dict[party['id']] = party['name']
        for parties in result_list.values():
            parties.sort(key=lambda p: p[1].lower())
            parties.insert(0, ('party:none', ''))
    return result_list, result_dict

class PartyData(object):
    party_choices, party_id_to_name = get_all_parties()

@@ -87,19 +87,8 @@
 join
-%0Aimport sys
 %0A%0Ada
@@ -154,54 +154,8 @@
 ))%0A%0A
-print %3E%3E sys.stderr, %22Loading MapIt data...%22%0A%0A
 def 
@@ -694,54 +694,8 @@
 ')%0A%0A
-print %3E%3E sys.stderr, %22Loading party data...%22%0A%0A
 def 

Remove debugging output for loading of static data