Skip to content

Commit

Permalink
Always use the common name of a country if available instead of its o…
Browse files Browse the repository at this point in the history
…fficial default value.
  • Loading branch information
Kevin Deldycke committed Apr 13, 2015
1 parent 2ba8a03 commit 8d1753c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ChangeLog

* Include internal fields disguised as properties when ``repr``-ing the
``Address`` object.
* Always use the common name of a country if available instead of its official
default value.


0.6.1 (2015-04-07)
Expand Down
9 changes: 8 additions & 1 deletion postal_address/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,15 @@ def country(self):

@property
def country_name(self):
""" Return country's name. """
""" Return country's name.
Common name always takes precedence over the default name, as the
latter isoften pompous, and sometimes false (i.e. not in sync with
current political situation).
"""
if self.country:
if hasattr(self.country, 'common_name'):
return self.country.common_name
return self.country.name
return None

Expand Down
2 changes: 2 additions & 0 deletions postal_address/tests/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ def test_country_alias_normalization(self):
# subdivision_code='TW-TTT')
for address in [address1, address2]: # address3]:
self.assertEqual(address.country_code, 'TW')
self.assertEqual(address.country_name, 'Taiwan')
self.assertEqual(address.subdivision_code, 'TW-TTT')

def test_subdivision_derived_fields(self):
Expand Down Expand Up @@ -651,6 +652,7 @@ def test_non_strict_mode_normalization(self):
self.assertEqual(address.postal_code, '10694')
self.assertEqual(address.city_name, 'Tainan City')
self.assertEqual(address.country_code, 'TW')
self.assertEqual(address.country_name, 'Taiwan')
self.assertEqual(address.subdivision_code, 'TW-TNN')

def test_rendering(self):
Expand Down

1 comment on commit 8d1753c

@kdeldycke
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see #10.

Please sign in to comment.