forked from CGM_Public/pretix_original
Allow to set privacy policy URL per language (#3146)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
# <https://www.gnu.org/licenses/>.
|
# <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.validators import URLValidator
|
||||||
from i18nfield.fields import I18nCharField, I18nTextField
|
from i18nfield.fields import I18nCharField, I18nTextField
|
||||||
from i18nfield.strings import LazyI18nString
|
from i18nfield.strings import LazyI18nString
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
@@ -69,3 +70,17 @@ class I18nAwareModelSerializer(ModelSerializer):
|
|||||||
|
|
||||||
I18nAwareModelSerializer.serializer_field_mapping[I18nCharField] = I18nField
|
I18nAwareModelSerializer.serializer_field_mapping[I18nCharField] = I18nField
|
||||||
I18nAwareModelSerializer.serializer_field_mapping[I18nTextField] = I18nField
|
I18nAwareModelSerializer.serializer_field_mapping[I18nTextField] = I18nField
|
||||||
|
|
||||||
|
|
||||||
|
class I18nURLField(I18nField):
|
||||||
|
def to_internal_value(self, value):
|
||||||
|
value = super().to_internal_value(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
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ import logging
|
|||||||
|
|
||||||
import i18nfield.forms
|
import i18nfield.forms
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.validators import URLValidator
|
||||||
from django.forms.models import ModelFormMetaclass
|
from django.forms.models import ModelFormMetaclass
|
||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from formtools.wizard.views import SessionWizardView
|
from formtools.wizard.views import SessionWizardView
|
||||||
from hierarkey.forms import HierarkeyForm
|
from hierarkey.forms import HierarkeyForm
|
||||||
|
from i18nfield.strings import LazyI18nString
|
||||||
|
|
||||||
from pretix.base.reldate import RelativeDateField, RelativeDateTimeField
|
from pretix.base.reldate import RelativeDateField, RelativeDateTimeField
|
||||||
|
|
||||||
@@ -222,3 +224,17 @@ class SecretKeySettingsField(forms.CharField):
|
|||||||
if value == SECRET_REDACTED:
|
if value == SECRET_REDACTED:
|
||||||
return
|
return
|
||||||
return super().run_validators(value)
|
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
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ from rest_framework import serializers
|
|||||||
from pretix.api.serializers.fields import (
|
from pretix.api.serializers.fields import (
|
||||||
ListMultipleChoiceField, UploadedFileField,
|
ListMultipleChoiceField, UploadedFileField,
|
||||||
)
|
)
|
||||||
from pretix.api.serializers.i18n import I18nField
|
from pretix.api.serializers.i18n import I18nField, I18nURLField
|
||||||
|
from pretix.base.forms import I18nURLFormField
|
||||||
from pretix.base.models.tax import VAT_ID_COUNTRIES, TaxRule
|
from pretix.base.models.tax import VAT_ID_COUNTRIES, TaxRule
|
||||||
from pretix.base.reldate import (
|
from pretix.base.reldate import (
|
||||||
RelativeDateField, RelativeDateTimeField, RelativeDateWrapper,
|
RelativeDateField, RelativeDateTimeField, RelativeDateWrapper,
|
||||||
@@ -1689,14 +1690,15 @@ DEFAULTS = {
|
|||||||
},
|
},
|
||||||
'privacy_url': {
|
'privacy_url': {
|
||||||
'default': None,
|
'default': None,
|
||||||
'type': str,
|
'type': LazyI18nString,
|
||||||
'form_class': forms.URLField,
|
'form_class': I18nURLFormField,
|
||||||
'form_kwargs': dict(
|
'form_kwargs': dict(
|
||||||
label=_("Privacy Policy URL"),
|
label=_("Privacy Policy URL"),
|
||||||
help_text=_("This should point e.g. to a part of your website that explains how you use data gathered in "
|
help_text=_("This should point e.g. to a part of your website that explains how you use data gathered in "
|
||||||
"your ticket shop."),
|
"your ticket shop."),
|
||||||
|
widget=I18nTextInput,
|
||||||
),
|
),
|
||||||
'serializer_class': serializers.URLField,
|
'serializer_class': I18nURLField,
|
||||||
},
|
},
|
||||||
'confirm_texts': {
|
'confirm_texts': {
|
||||||
'default': LazyI18nStringList(),
|
'default': LazyI18nStringList(),
|
||||||
|
|||||||
Reference in New Issue
Block a user