misc: add converters (#52226)

To simplify url patterns.
This commit is contained in:
Benjamin Dauvergne 2023-12-21 19:54:09 +01:00
parent 6cb3259683
commit b3a791ef8f
2 changed files with 24 additions and 0 deletions

View File

@ -28,3 +28,8 @@ class Authentic2Config(AppConfig):
def ready(self):
plugins.init()
debug.HIDDEN_SETTINGS = re.compile('API|TOKEN|KEY|SECRET|PASS|PROFANITIES_LIST|SIGNATURE|LDAP')
# register convertes
from authentic2.utils.converters import register_converters
register_converters()

View File

@ -0,0 +1,19 @@
# Authentic2 © Entr'ouvert
from django.urls.converters import SlugConverter, register_converter
class ObjectUUID:
regex = r'[0-9a-f]{32}'
def to_python(self, value):
return value.replace('-', '')
def to_url(self, value):
return str(value)
def register_converters():
register_converter(ObjectUUID, 'a2_uuid')
# legacy, some instances have non UUID like string as User.uuid
register_converter(SlugConverter, 'user_uuid')