Skip to content

Commit

Permalink
Merge pull request #75 from hasier/unknown-locale-patch
Browse files Browse the repository at this point in the history
Fix get_formatting_definition() failing if locale is not found
  • Loading branch information
spookylukey committed Jan 1, 2017
2 parents ef02dbc + d03d39b commit 2381581
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 4 additions & 6 deletions moneyed/localization.py
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal, ROUND_HALF_EVEN
import moneyed

DEFAULT = "default"
DEFAULT = "DEFAULT"


class CurrencyFormatter(object):
Expand Down Expand Up @@ -49,11 +49,9 @@ def get_sign_definition(self, currency_code, locale):
return ('', " %s" % currency_code)

def get_formatting_definition(self, locale):
locale = locale.upper()
if locale in self.formatting_definitions:
return self.formatting_definitions.get(locale)
else:
return self.formatting_definitions.get(DEFAULT)
if locale.upper() not in self.formatting_definitions:
locale = DEFAULT
return self.formatting_definitions.get(locale.upper())

def format(self, money, include_symbol=True, locale=DEFAULT,
decimal_places=None, rounding_method=None):
Expand Down
2 changes: 2 additions & 0 deletions moneyed/test_moneyed_classes.py
Expand Up @@ -130,6 +130,8 @@ def test_format_money(self):
assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
# No decimal point without fractional part
assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
# Locale format not included, should fallback to DEFAULT
assert format_money(self.one_million_bucks, locale='es_ES') == 'US$1,000,000.00'
# locale == pl_PL
one_million_pln = Money('1000000', 'PLN')
# Two decimal places by default
Expand Down

0 comments on commit 2381581

Please sign in to comment.