forked from CGM_Public/pretix_original
Tax rule editor: Use cacehd countries
This commit is contained in:
@@ -11,7 +11,6 @@ from django.utils.html import escape
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.timezone import get_current_timezone_name
|
from django.utils.timezone import get_current_timezone_name
|
||||||
from django.utils.translation import gettext, gettext_lazy as _, pgettext_lazy
|
from django.utils.translation import gettext, gettext_lazy as _, pgettext_lazy
|
||||||
from django_countries import Countries
|
|
||||||
from django_countries.fields import LazyTypedChoiceField
|
from django_countries.fields import LazyTypedChoiceField
|
||||||
from i18nfield.forms import (
|
from i18nfield.forms import (
|
||||||
I18nForm, I18nFormField, I18nFormSetMixin, I18nTextarea, I18nTextInput,
|
I18nForm, I18nFormField, I18nFormSetMixin, I18nTextarea, I18nTextInput,
|
||||||
@@ -32,6 +31,7 @@ from pretix.control.forms import (
|
|||||||
SplitDateTimePickerWidget,
|
SplitDateTimePickerWidget,
|
||||||
)
|
)
|
||||||
from pretix.control.forms.widgets import Select2
|
from pretix.control.forms.widgets import Select2
|
||||||
|
from pretix.helpers.countries import CachedCountries
|
||||||
from pretix.multidomain.models import KnownDomain
|
from pretix.multidomain.models import KnownDomain
|
||||||
from pretix.multidomain.urlreverse import build_absolute_uri
|
from pretix.multidomain.urlreverse import build_absolute_uri
|
||||||
from pretix.plugins.banktransfer.payment import BankTransfer
|
from pretix.plugins.banktransfer.payment import BankTransfer
|
||||||
@@ -1090,12 +1090,13 @@ class CommentForm(I18nModelForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CountriesAndEU(Countries):
|
class CountriesAndEU(CachedCountries):
|
||||||
override = {
|
override = {
|
||||||
'ZZ': _('Any country'),
|
'ZZ': _('Any country'),
|
||||||
'EU': _('European Union')
|
'EU': _('European Union')
|
||||||
}
|
}
|
||||||
first = ['ZZ', 'EU']
|
first = ['ZZ', 'EU']
|
||||||
|
cache_subkey = 'with_any_or_eu'
|
||||||
|
|
||||||
|
|
||||||
class TaxRuleLineForm(forms.Form):
|
class TaxRuleLineForm(forms.Form):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from django_countries.fields import CountryField
|
|||||||
|
|
||||||
class CachedCountries(Countries):
|
class CachedCountries(Countries):
|
||||||
_cached_lists = {}
|
_cached_lists = {}
|
||||||
|
cache_subkey = None
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""
|
"""
|
||||||
@@ -14,6 +15,8 @@ class CachedCountries(Countries):
|
|||||||
slow.
|
slow.
|
||||||
"""
|
"""
|
||||||
cache_key = "countries:all:{}".format(get_language())
|
cache_key = "countries:all:{}".format(get_language())
|
||||||
|
if self.cache_subkey:
|
||||||
|
cache_key += ":" + self.cache_subkey
|
||||||
if cache_key in self._cached_lists:
|
if cache_key in self._cached_lists:
|
||||||
yield from self._cached_lists[cache_key]
|
yield from self._cached_lists[cache_key]
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user