Description: Don't use the shipped static lists for the country-codes, instead 
 gather the data at runtime by parsing the XML files shipped with the 
 iso-codes package.
 Translations for the countries names are also taken from iso-codes.
Author: Fladischer Michael <FladischerMichael@fladi.at>
Forwarded: not-needed
Last-Update: 2010-04-20

Index: django-countries/django_countries/settings.py
===================================================================
--- django-countries.orig/django_countries/settings.py	2010-04-20 11:36:57.513764350 +0200
+++ django-countries/django_countries/settings.py	2010-04-20 11:37:14.377763439 +0200
@@ -1,3 +1,4 @@
+import os
 from django.conf import settings
 
 
@@ -11,5 +12,11 @@
         prefix = '%s/' % prefix
     return '%s%s' % (prefix, url)
 
+def _build_iso_xml():
+    if hasattr(settings, 'COUNTRIES_ISO_XML'):
+        return settings.COUNTRIES_ISO_XML
+    else:
+        return '/usr/share/xml/iso-codes/iso_3166.xml'
 
 FLAG_URL = _build_flag_url()
+ISO_XML = _build_iso_xml()
Index: django-countries/django_countries/countries.py
===================================================================
--- django-countries.orig/django_countries/countries.py	2010-04-20 11:37:25.497767986 +0200
+++ django-countries/django_countries/countries.py	2010-04-20 11:39:15.877763941 +0200
@@ -1,3 +1,23 @@
+from gettext import dgettext as _
+
+from xml.dom.minidom import parse
+
+from django_countries import settings
+
+# Nicely titled (and translated) country names.
+COUNTRIES = []
+COUNTRIES_PLUS = []
+OFFICIAL_COUNTRIES = {}
+
+for node in parse(settings.ISO_XML).getElementsByTagName('iso_3166_entry'):
+    _code = node.getAttribute('alpha_2_code')
+    _name = _('iso_3166', node.getAttribute('name'))
+    COUNTRIES.append((_code, _name))
+    COUNTRIES_PLUS.append((_code, _name))
+    OFFICIAL_COUNTRIES[_code.upper()] = _name.upper()
+
+'''
+# Upstream shipped static lists of countries.
 from django.utils.translation import ugettext_lazy as _
 
 # Nicely titled (and translatable) country names.
@@ -764,3 +784,5 @@
     'ZM': u'ZAMBIA',
     'ZW': u'ZIMBABWE',
 }
+'''
+
