diff --git a/core/converters.py b/core/converters.py index d2ad4494..b161eec6 100644 --- a/core/converters.py +++ b/core/converters.py @@ -1,19 +1,16 @@ -class FourDigitYearConverter: - regex = "[0-9]{4}" +from django.urls.converters import IntConverter, StringConverter - def to_python(self, value): - return int(value) + +class FourDigitYearConverter(IntConverter): + regex = "[0-9]{4}" def to_url(self, value): return str(value).zfill(4) -class TwoDigitMonthConverter: +class TwoDigitMonthConverter(IntConverter): regex = "[0-9]{2}" - def to_python(self, value): - return int(value) - def to_url(self, value): return str(value).zfill(2) @@ -28,3 +25,9 @@ class BooleanStringConverter: def to_url(self, value): return str(value) + + +class ResultConverter(StringConverter): + """Converter whose regex match either "success" or "failure".""" + + regex = "(success|failure)" diff --git a/eboutic/converters.py b/eboutic/converters.py deleted file mode 100644 index fec67ed8..00000000 --- a/eboutic/converters.py +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright 2022 -# - Maréchal