mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
* Fix #294 - blacklist for slug validation * Fix #294 - blacklist for slug validation * fix for failing test
This commit is contained in:
committed by
Raphael Michel
parent
4820a8423f
commit
9662b956ed
48
src/pretix/base/validators.py
Normal file
48
src/pretix/base/validators.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class BlacklistValidator:
|
||||
|
||||
blacklist = []
|
||||
|
||||
def __call__(self, value):
|
||||
# Validation logic
|
||||
if value in self.blacklist:
|
||||
raise ValidationError(
|
||||
_('This slug has an invalid value: %(value)s.'),
|
||||
code='invalid',
|
||||
params={'value': value},
|
||||
)
|
||||
|
||||
|
||||
class EventSlugBlacklistValidator(BlacklistValidator):
|
||||
|
||||
blacklist = [
|
||||
'download',
|
||||
'healthcheck',
|
||||
'locale',
|
||||
'control',
|
||||
'redirect',
|
||||
'jsi18n',
|
||||
'metrics',
|
||||
'_global',
|
||||
'__debug__'
|
||||
]
|
||||
|
||||
|
||||
class OrganizerSlugBlacklistValidator(BlacklistValidator):
|
||||
|
||||
blacklist = [
|
||||
'download',
|
||||
'healthcheck',
|
||||
'locale',
|
||||
'control',
|
||||
'pretixdroid',
|
||||
'redirect',
|
||||
'jsi18n',
|
||||
'metrics',
|
||||
'_global',
|
||||
'__debug__',
|
||||
'about'
|
||||
]
|
||||
Reference in New Issue
Block a user