Пример #1
0
    def test_format_money(self):
        # Two decimal places by default
        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 == pl_PL
        one_million_pln = Money('1000000', 'PLN')
        # Two decimal places by default
        assert format_money(one_million_pln,
                            locale='pl_PL') == '1 000 000,00 zł'

        # overriden sign/format locale display default sign with locale group parameter
        assert format_money(self.one_million_bucks,
                            locale='pl_PL') == 'US$1 000 000,00'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_bucks,
                            locale='fr_FR') == 'US$1,000,000.00'

        # No decimal point without fractional part
        assert format_money(one_million_pln, locale='pl_PL',
                            decimal_places=0) == '1 000 000 zł'

        # add different sign for money USD in locale pl_PL
        _sign('pl_PL', moneyed.USD, prefix='$')
        assert format_money(self.one_million_bucks,
                            locale='pl_PL') == '$1 000 000,00'

        # default locale display correct money sign with default group parameter
        assert format_money(self.one_million_euros) == '1,000,000.00 €'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_euros,
                            locale='fr_FR') == '1,000,000.00 €'
        # overriden sign/locale locale display default money sign with locale group parameter
        assert format_money(self.one_million_euros,
                            locale='en_US') == '1,000,000.00 €'

        # add format for fr_FR locale
        _format("fr_FR",
                group_size=3,
                group_separator=" ",
                decimal_point=",",
                positive_sign="",
                trailing_positive_sign="",
                negative_sign="-",
                trailing_negative_sign="",
                rounding_method=ROUND_HALF_EVEN)
        # overriden format locale display correct sign with locale group parameter
        assert format_money(self.one_million_euros,
                            locale='fr_FR') == '1 000 000,00 €'
    def test_format_money(self):
        # Two decimal places by default
        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 == pl_PL
        one_million_pln = Money('1000000', 'PLN')
        # Two decimal places by default
        assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'

        # overriden sign/format locale display default sign with locale group parameter
        assert format_money(self.one_million_bucks, locale='pl_PL') == 'US$1 000 000,00'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_bucks, locale='fr_FR') == 'US$1,000,000.00'

        # No decimal point without fractional part
        assert format_money(one_million_pln, locale='pl_PL', decimal_places=0) == '1 000 000 zł'

        # add different sign for money USD in locale pl_PL
        _sign('pl_PL', moneyed.USD, prefix='$')
        assert format_money(self.one_million_bucks, locale='pl_PL') == '$1 000 000,00'

        # default locale display correct money sign with default group parameter
        assert format_money(self.one_million_euros) == '1,000,000.00 €'
        # non overriden sign/format locale display default money sign with default group parameter
        assert format_money(self.one_million_euros, locale='fr_FR') == '1,000,000.00 €'
        # overriden sign/locale locale display default money sign with locale group parameter
        assert format_money(self.one_million_euros, locale='en_US') == '1,000,000.00 €'

        # add format for fr_FR locale
        _format("fr_FR", group_size=3, group_separator=" ", decimal_point=",",
                positive_sign="", trailing_positive_sign="",
                negative_sign="-", trailing_negative_sign="",
                rounding_method=ROUND_HALF_EVEN)
        # overriden format locale display correct sign with locale group parameter
        assert format_money(self.one_million_euros, locale='fr_FR') == '1 000 000,00 €'
Пример #3
0

# The default currency formatting of py-moneyed/djmoney doesn't do
# what we want, so we set up a custom one here, applying a consistent
# format that always prefixes the three-letter currency code and
# symbol.
DJANGO = "django"

_format(DJANGO, group_size=3, group_separator=",", decimal_point=".",
        positive_sign="", trailing_positive_sign="",
        negative_sign="-", trailing_negative_sign="",
        rounding_method=ROUND_HALF_EVEN)

# The DSF mostly only deals in USD with occasional grants iN EUR, but
# we set up a few other currencies here just to be safe.
#
# Any currencies not defined here will fall back to the py-moneyed
# default formatter.
_sign(DJANGO, moneyed.AUD, prefix='AUD $')
_sign(DJANGO, moneyed.CAD, prefix='CAD $')
_sign(DJANGO, moneyed.EUR, prefix='EUR €')
_sign(DJANGO, moneyed.GBP, prefix='GBP £')
_sign(DJANGO, moneyed.JPY, prefix='JPY ¥')
_sign(DJANGO, moneyed.NZD, prefix='NZD $')
_sign(DJANGO, moneyed.USD, prefix='USD $')


@register.filter
def currency(value):
    return format_money(value, locale=DJANGO)
Пример #4
0
from decimal import ROUND_HALF_EVEN

import moneyed
from moneyed.localization import _sign, _format

_sign("en_GB", moneyed.GBP, prefix="£")

_format(
    "en_GB",
    group_size=3,
    group_separator=",",
    decimal_point=".",
    positive_sign="",
    trailing_positive_sign="",
    negative_sign="-",
    trailing_negative_sign="",
    rounding_method=ROUND_HALF_EVEN,
)
Пример #5
0
LANGUAGE_CODE = 'es-AR'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

_sign("DEFAULT", moneyed.ARS, prefix='$')
_sign("DEFAULT", moneyed.USD, prefix='US$')

moneyed.add_currency('ARS', '032', 'Peso Argentino', ['ARGENTINA'])

CURRENCIES = ('ARS', 'USD')

TINYMCE_DEFAULT_CONFIG.update({
    'toolbar':
    'undo redo | '
    'formatselect | '
    'bold italic underline strikethrough | '
    'fontselect fontsizeselect forecolor backcolor | '
    'alignleft aligncenter alignright alignjustify | '
    'bullist numlist outdent indent | '
    'removeformat | '
Пример #6
0
# symbol.
DJANGO = "django"

_format(DJANGO,
        group_size=3,
        group_separator=",",
        decimal_point=".",
        positive_sign="",
        trailing_positive_sign="",
        negative_sign="-",
        trailing_negative_sign="",
        rounding_method=ROUND_HALF_EVEN)

# The DSF mostly only deals in USD with occasional grants iN EUR, but
# we set up a few other currencies here just to be safe.
#
# Any currencies not defined here will fall back to the py-moneyed
# default formatter.
_sign(DJANGO, moneyed.AUD, prefix='AUD $')
_sign(DJANGO, moneyed.CAD, prefix='CAD $')
_sign(DJANGO, moneyed.EUR, prefix='EUR €')
_sign(DJANGO, moneyed.GBP, prefix='GBP £')
_sign(DJANGO, moneyed.JPY, prefix='JPY ¥')
_sign(DJANGO, moneyed.NZD, prefix='NZD $')
_sign(DJANGO, moneyed.USD, prefix='USD $')


@register.filter
def currency(value):
    return format_money(value, locale=DJANGO)
Пример #7
0
from decimal import ROUND_HALF_EVEN

import moneyed
from moneyed.localization import _sign, _format

_sign('en_GB', moneyed.GBP, prefix='£')

_format('en_GB',
        group_size=3,
        group_separator=',',
        decimal_point='.',
        positive_sign='',
        trailing_positive_sign='',
        negative_sign='-',
        trailing_negative_sign='',
        rounding_method=ROUND_HALF_EVEN)