Source code for superdjango.contrib.i18n.currencies.forms

# Imports

from django import forms
from django.conf import settings
from .choices import COMMON_CURRENCY_CHOICES

# Exports

__all__ = (
    "CurrencyField",
)

# Constants

DEFAULT_CURRENCY = getattr(settings, "SUPERDJANGO_I18N_DEFAULT_CURRENCY_CODE", None)

# Fields


[docs]class CurrencyField(forms.ChoiceField): """Provide country choices."""
[docs] def __init__(self, **kwargs): """``choices`` defaults to ``COMMON_CURRENCY_CHOICES``, and ``initial`` defaults to ``SUPERDJANGO_I18N_DEFAULT_CURRENCY_CODE`` if defined in settings. """ kwargs.setdefault("choices", COMMON_CURRENCY_CHOICES) kwargs.setdefault("initial", DEFAULT_CURRENCY) super().__init__(**kwargs)