def _sign_definition(self): from moneyed.localization import CurrencyFormatter cf = CurrencyFormatter() try: return cf.get_sign_definition(self.code, get_current_locale()) except IndexError: return ("", "")
def get_sign_definition(money_dict): if "_sign_definition" not in money_dict: try: money_dict["_sign_definition"] = _cf.get_sign_definition( money_dict["code"], get_current_locale()) except IndexError: money_dict["_sign_definition"] = ("", "") return money_dict["_sign_definition"]
def coerce_string(value): if isinstance(value, Money): locale = get_current_locale() text = format_money( money=value, decimal_places=value.decimal_places, locale=locale, ) return text return graphene.String.coerce_string(value)
def __init__(self, decimals=None, currency_field=None, locale=None, include_symbol=True, target_rate=None, target_currency=None, *args, **kwargs): super().__init__(*args, **kwargs) self.decimals = decimals if decimals is not None else self.decimals self.currency_field = currency_field or self.currency_field self.locale = locale or get_current_locale() self.include_symbol = include_symbol self.target_rate = target_rate or self.target_rate self.target_currency = target_currency or self.target_currency
def test_get_current_locale(locale, expected): with override(locale): assert get_current_locale() == expected
def test_legacy_get_current_locale(locale, expected): with override(locale): assert get_current_locale(for_babel=False) == expected