Hide keyboard shortcuts

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`_. 

3 

4.. _path converters: https://docs.djangoproject.com/en/stable/topics/http/urls/#registering-custom-path-converters 

5 

6""" 

7 

8# Converters 

9 

10 

11class FourDigitYearConverter: 

12 """Path converter for a year in YYYY format. Straight from the Django documentation.""" 

13 

14 regex = '[0-9]{4}' 

15 

16 # noinspection PyMethodMayBeStatic 

17 def to_python(self, value): 

18 return int(value) 

19 

20 # noinspection PyMethodMayBeStatic 

21 def to_url(self, value): 

22 return '%04d' % value 

23 

24 

25class MD5Converter: 

26 """Path converter for matching an MD5 hex digest.""" 

27 

28 regex = r"[\d\w]{32}" 

29 

30 # noinspection PyMethodMayBeStatic 

31 def to_python(self, value): 

32 return str(value) 

33 

34 # noinspection PyMethodMayBeStatic 

35 def to_url(self, value): 

36 return "%s" % value 

37 

38 

39class VersionConverter: 

40 """Path converter for matching a `semantic versioning <semver.org>`_ string.""" 

41 

42 regex = r"[\d\w.-]+" 

43 

44 # noinspection PyMethodMayBeStatic 

45 def to_python(self, value): 

46 """Returns the version as a ``str``.""" 

47 return str(value) 

48 

49 # noinspection PyMethodMayBeStatic 

50 def to_url(self, value): 

51 return "%s" % value