Merge lp:~dholbach/loco-team-portal/614236 into lp:loco-team-portal

Proposed by Daniel Holbach
Status: Merged
Approved by: Michael Hall
Approved revision: 224
Merged at revision: 224
Proposed branch: lp:~dholbach/loco-team-portal/614236
Merge into: lp:loco-team-portal
Diff against target: 38 lines (+20/-4)
1 file modified
loco_directory/teams/management/commands/update-countries.py (+20/-4)
To merge this branch: bzr merge lp:~dholbach/loco-team-portal/614236
Reviewer Review Type Date Requested Status
LoCo Team Portal Developers Pending
Review via email: mp+31959@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/teams/management/commands/update-countries.py'
2--- loco_directory/teams/management/commands/update-countries.py 2010-06-22 07:33:00 +0000
3+++ loco_directory/teams/management/commands/update-countries.py 2010-08-06 13:47:42 +0000
4@@ -8,6 +8,19 @@
5 import os
6 import sys
7
8+def create_country(common_name, name):
9+ if common_name:
10+ country = models.Country(name=common_name)
11+ else:
12+ country = models.Country(name=name)
13+ country.save()
14+
15+def rename_country(common_name, name):
16+ if common_name:
17+ country = models.Country.objects.get(name=name)
18+ country.name = common_name
19+ country.save()
20+
21 class Command(NoArgsCommand):
22 help = "Update list of continents and countries."
23
24@@ -36,7 +49,10 @@
25 doc = xml.dom.minidom.parse(country_list)
26 country_entries = doc.getElementsByTagName('iso_3166_entry')
27 for country_entry in country_entries:
28- if country_entry.getAttribute('name'):
29- country, created = models.Country.objects.get_or_create(name=country_entry.getAttribute('name'))
30- if created:
31- country.save()
32+ common_name = country_entry.getAttribute('common_name')
33+ name = country_entry.getAttribute('name')
34+ if not models.Country.objects.filter(name=common_name):
35+ if not models.Country.objects.filter(name=name):
36+ create_country(common_name, name)
37+ else:
38+ rename_country(common_name, name)

Subscribers

People subscribed via source and target branches