forked from openedx-unsupported/edx-analytics-data-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced iso3166 with django-countries
This change ensures the country names in the CSVs match those displayed in Insights.
- Loading branch information
Clinton Blackburn
committed
Dec 2, 2014
1 parent
bf4f5ba
commit 891d814
Showing
7 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
from iso3166 import Country | ||
""" | ||
This file holds constants and helper methods related to countries. All codes are assumed to be valid ISO 3166 country | ||
codes. | ||
""" | ||
from collections import namedtuple | ||
from django_countries import countries | ||
|
||
Country = namedtuple('Country', 'name, alpha2, alpha3, numeric') | ||
|
||
UNKNOWN_COUNTRY_CODE = u'UNKNOWN' | ||
UNKNOWN_COUNTRY = Country(UNKNOWN_COUNTRY_CODE, None, None, None) | ||
|
||
|
||
def _get_country_property(code, property_name): | ||
return unicode(getattr(countries, property_name)(code)) | ||
|
||
|
||
def get_country(code): | ||
if not code: | ||
return UNKNOWN_COUNTRY | ||
|
||
name = _get_country_property(code, 'name') | ||
if not name: | ||
return UNKNOWN_COUNTRY | ||
|
||
args = [] | ||
properties = ['alpha2', 'alpha3', 'numeric'] | ||
for property_name in properties: | ||
args.append(_get_country_property(code, property_name)) | ||
|
||
return Country(name, *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters