Exemplo n.º 1
0
    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 ("", "")
Exemplo n.º 2
0
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"]
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
def test_get_current_locale(locale, expected):
    with override(locale):
        assert get_current_locale() == expected
Exemplo n.º 6
0
def test_legacy_get_current_locale(locale, expected):
    with override(locale):
        assert get_current_locale(for_babel=False) == expected
Exemplo n.º 7
0
def test_get_current_locale(locale, expected):
    with override(locale):
        assert get_current_locale() == expected