Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Additional `path converters`_.
4.. _path converters: https://docs.djangoproject.com/en/stable/topics/http/urls/#registering-custom-path-converters
6"""
8# Converters
11class FourDigitYearConverter:
12 """Path converter for a year in YYYY format. Straight from the Django documentation."""
14 regex = '[0-9]{4}'
16 # noinspection PyMethodMayBeStatic
17 def to_python(self, value):
18 return int(value)
20 # noinspection PyMethodMayBeStatic
21 def to_url(self, value):
22 return '%04d' % value
25class MD5Converter:
26 """Path converter for matching an MD5 hex digest."""
28 regex = r"[\d\w]{32}"
30 # noinspection PyMethodMayBeStatic
31 def to_python(self, value):
32 return str(value)
34 # noinspection PyMethodMayBeStatic
35 def to_url(self, value):
36 return "%s" % value
39class VersionConverter:
40 """Path converter for matching a `semantic versioning <semver.org>`_ string."""
42 regex = r"[\d\w.-]+"
44 # noinspection PyMethodMayBeStatic
45 def to_python(self, value):
46 """Returns the version as a ``str``."""
47 return str(value)
49 # noinspection PyMethodMayBeStatic
50 def to_url(self, value):
51 return "%s" % value