diff --git a/src/pretix/control/forms/event.py b/src/pretix/control/forms/event.py index ee0b360c5a..55035a8903 100644 --- a/src/pretix/control/forms/event.py +++ b/src/pretix/control/forms/event.py @@ -11,7 +11,6 @@ from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.timezone import get_current_timezone_name from django.utils.translation import gettext, gettext_lazy as _, pgettext_lazy -from django_countries import Countries from django_countries.fields import LazyTypedChoiceField from i18nfield.forms import ( I18nForm, I18nFormField, I18nFormSetMixin, I18nTextarea, I18nTextInput, @@ -32,6 +31,7 @@ from pretix.control.forms import ( SplitDateTimePickerWidget, ) from pretix.control.forms.widgets import Select2 +from pretix.helpers.countries import CachedCountries from pretix.multidomain.models import KnownDomain from pretix.multidomain.urlreverse import build_absolute_uri from pretix.plugins.banktransfer.payment import BankTransfer @@ -1090,12 +1090,13 @@ class CommentForm(I18nModelForm): } -class CountriesAndEU(Countries): +class CountriesAndEU(CachedCountries): override = { 'ZZ': _('Any country'), 'EU': _('European Union') } first = ['ZZ', 'EU'] + cache_subkey = 'with_any_or_eu' class TaxRuleLineForm(forms.Form): diff --git a/src/pretix/helpers/countries.py b/src/pretix/helpers/countries.py index 2afdc5f94b..7769d8919d 100644 --- a/src/pretix/helpers/countries.py +++ b/src/pretix/helpers/countries.py @@ -6,6 +6,7 @@ from django_countries.fields import CountryField class CachedCountries(Countries): _cached_lists = {} + cache_subkey = None def __iter__(self): """ @@ -14,6 +15,8 @@ class CachedCountries(Countries): slow. """ cache_key = "countries:all:{}".format(get_language()) + if self.cache_subkey: + cache_key += ":" + self.cache_subkey if cache_key in self._cached_lists: yield from self._cached_lists[cache_key] return