Daniel Holbach has proposed merging lp:~dholbach/loco-directory/614236 into
lp:loco-directory.
Requested reviews:
loco-directory-dev (loco-directory-dev)
Related bugs:
#614236 Wrong Country Name. (Taiwan)
https://bugs.launchpad.net/bugs/614236
--
https://code.launchpad.net/~dholbach/loco-directory/614236/+merge/31959
Your team loco-directory-dev is requested to review the proposed merge of
lp:~dholbach/loco-directory/614236 into lp:loco-directory.
=== modified file 'loco_directory/teams/management/commands/update-countries.py'
--- loco_directory/teams/management/commands/update-countries.py 2010-06-22 07:33:00 +0000
+++ loco_directory/teams/management/commands/update-countries.py 2010-08-06 13:47:42 +0000
@@ -8,6 +8,19 @@
import os
import sys
+def create_country(common_name, name):
+ if common_name:
+ country = models.Country(name=common_name)
+ else:
+ country = models.Country(name=name)
+ country.save()
+
+def rename_country(common_name, name):
+ if common_name:
+ country = models.Country.objects.get(name=name)
+ country.name = common_name
+ country.save()
+
class Command(NoArgsCommand):
help = "Update list of continents and countries."
@@ -36,7 +49,10 @@
doc = xml.dom.minidom.parse(country_list)
country_entries = doc.getElementsByTagName('iso_3166_entry')
for country_entry in country_entries:
- if country_entry.getAttribute('name'):
- country, created = models.Country.objects.get_or_create(name=country_entry.getAttribute('name'))
- if created:
- country.save()
+ common_name = country_entry.getAttribute('common_name')
+ name = country_entry.getAttribute('name')
+ if not models.Country.objects.filter(name=common_name):
+ if not models.Country.objects.filter(name=name):
+ create_country(common_name, name)
+ else:
+ rename_country(common_name, name)
_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help : https://help.launchpad.net/ListHelp