mirror of
https://github.com/pretix/pretix.git
synced 2026-05-26 18:43:59 +00:00
Add NoUrlValidator to validators (#6208)
This commit is contained in:
committed by
GitHub
parent
c7b82fdc97
commit
909ce5b27d
@@ -24,10 +24,12 @@ import calendar
|
|||||||
from dateutil.rrule import DAILY, MONTHLY, WEEKLY, YEARLY, rrule, rrulestr
|
from dateutil.rrule import DAILY, MONTHLY, WEEKLY, YEARLY, rrule, rrulestr
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import RegexValidator, validate_email
|
||||||
from django.utils.deconstruct import deconstructible
|
from django.utils.deconstruct import deconstructible
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from pretix.base.templatetags.rich_text import URL_RE
|
||||||
|
|
||||||
# This file is based on an earlier version of pretix which was released under the Apache License 2.0. The full text of
|
# This file is based on an earlier version of pretix which was released under the Apache License 2.0. The full text of
|
||||||
# the Apache License 2.0 can be obtained at <http://www.apache.org/licenses/LICENSE-2.0>.
|
# the Apache License 2.0 can be obtained at <http://www.apache.org/licenses/LICENSE-2.0>.
|
||||||
#
|
#
|
||||||
@@ -113,6 +115,33 @@ def multimail_validate(val):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
class RegexValidatorInverseMatchAndParam(RegexValidator):
|
||||||
|
inverse_match = True
|
||||||
|
|
||||||
|
def __call__(self, value):
|
||||||
|
regex_matches = self.regex.search(str(value))
|
||||||
|
if regex_matches:
|
||||||
|
raise ValidationError(
|
||||||
|
self.message,
|
||||||
|
code=self.code,
|
||||||
|
params={
|
||||||
|
"value": value,
|
||||||
|
"match": regex_matches.group(0) if regex_matches else "",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NoUrlValidator(RegexValidatorInverseMatchAndParam):
|
||||||
|
regex = URL_RE
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
if not kwargs.get("message"):
|
||||||
|
kwargs["message"] = _('You entered an URL, which is not allowed. Please remove %(match)s from your input.')
|
||||||
|
if not kwargs.get("code"):
|
||||||
|
kwargs["code"] = "contains_url"
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RRuleValidator:
|
class RRuleValidator:
|
||||||
def __init__(self, enforce_simple=False):
|
def __init__(self, enforce_simple=False):
|
||||||
self.enforce_simple = enforce_simple
|
self.enforce_simple = enforce_simple
|
||||||
|
|||||||
Reference in New Issue
Block a user