示例#1
0
    def handle(self, **options):
        force = options.get("force", False)
        currency = options["currency"]

        if not force:
            try:
                validate_currency(currency)
            except UnknownCurrencyError:
                raise CommandError(
                    "Unknown currency. "
                    "Use `--force` flag to force migration currencies."
                )

        Checkout.objects.update(currency=currency)
        GiftCard.objects.update(currency=currency)
        Order.objects.update(currency=currency)
        OrderLine.objects.update(currency=currency)
        Payment.objects.update(currency=currency)
        Transaction.objects.update(currency=currency)
示例#2
0
def test_validate_currency():
    validate_currency('EUR')

    with pytest.raises(UnknownCurrencyError) as excinfo:
        validate_currency('FUU')
    assert excinfo.value.args[0] == "Unknown currency 'FUU'."
示例#3
0
def test_validate_currency():
    validate_currency('EUR')

    with pytest.raises(UnknownCurrencyError) as excinfo:
        validate_currency('FUU')
    assert excinfo.value.args[0] == "Unknown currency 'FUU'."
示例#4
0
    for varname in ['LC_ALL', 'LC_MONETARY', 'LANG']:
        val = os.environ.get(varname, '').strip()
        if val != '' and val != 'C' and not val.startswith('C.'):
            logger.debug('Setting LOCALE_NAME to %s from env var %s', val,
                         varname)
            LOCALE_NAME = val
            break
    if LOCALE_NAME is None:
        logger.debug('LOCALE_NAME not set; defaulting to en_US')
        LOCALE_NAME = 'en_US'

# Check for a valid locale
try:
    Locale.parse(LOCALE_NAME)
except UnknownLocaleError:
    raise SystemExit(
        'ERROR: LOCALE_NAME setting of "%s" is not a valid BCP 47 Language Tag.'
        ' See <https://tools.ietf.org/html/bcp47> for more information.' %
        LOCALE_NAME)

# Check for a valid currency code
try:
    validate_currency(CURRENCY_CODE)
except UnknownCurrencyError:
    raise SystemExit(
        'ERROR: CURRENCY_CODE setting of "%s" is not a valid currency code. See'
        ' <https://en.wikipedia.org/wiki/ISO_4217> for more information and '
        'a list of valid codes.' % CURRENCY_CODE)

logger.debug('Done loading settings.')