Source code for common.converters

__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"


from django.urls.converters import StringConverter


[docs]class UnicodeSlugConverter(StringConverter): regex = "[-\w_]+"
[docs]class FourDigitYearConverter: regex = "[0-9]{4}"
[docs] def to_python(self, value): return int(value)
[docs] def to_url(self, value): return "%04d" % int(value)
[docs]class TwoDigitMonthConverter: regex = "0[1-9]|1[0-2]"
[docs] def to_python(self, value): return int(value)
[docs] def to_url(self, value): return str(value).zfill(2)
[docs]class TwoDigitDayConverter: regex = "0[1-9]|[1-2][0-9]|3[0-1]"
[docs] def to_python(self, value): return int(value)
[docs] def to_url(self, value): return str(value).zfill(2)