Allow to set privacy policy URL per language (#3146)

This commit is contained in:
Raphael Michel
2023-03-06 12:02:52 +01:00
committed by GitHub
parent 9bed40fa09
commit 81a5e263cb
3 changed files with 37 additions and 4 deletions

View File

@@ -36,11 +36,13 @@ import logging
import i18nfield.forms
from django import forms
from django.core.validators import URLValidator
from django.forms.models import ModelFormMetaclass
from django.utils.crypto import get_random_string
from django.utils.translation import gettext_lazy as _
from formtools.wizard.views import SessionWizardView
from hierarkey.forms import HierarkeyForm
from i18nfield.strings import LazyI18nString
from pretix.base.reldate import RelativeDateField, RelativeDateTimeField
@@ -222,3 +224,17 @@ class SecretKeySettingsField(forms.CharField):
if value == SECRET_REDACTED:
return
return super().run_validators(value)
class I18nURLFormField(i18nfield.forms.I18nFormField):
def clean(self, value) -> LazyI18nString:
value = super().clean(value)
if not value:
return value
if isinstance(value.data, dict):
for v in value.data.values():
if v:
URLValidator()(v)
else:
URLValidator()(value.data)
return value