mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-15 22:39:25 +00:00
Mise à jour de février (#581)
Co-authored-by: Thomas Girod <thgirod@hotmail.com> Co-authored-by: Julien Constant <julienconstant190@gmail.com> Co-authored-by: Skia <skia@hya.sk>
This commit is contained in:
35
core/converters.py
Normal file
35
core/converters.py
Normal file
@ -0,0 +1,35 @@
|
||||
from core.models import Page
|
||||
|
||||
|
||||
class FourDigitYearConverter:
|
||||
regex = "[0-9]{4}"
|
||||
|
||||
def to_python(self, value):
|
||||
return int(value)
|
||||
|
||||
def to_url(self, value):
|
||||
return str(value).zfill(4)
|
||||
|
||||
|
||||
class TwoDigitMonthConverter:
|
||||
regex = "[0-9]{2}"
|
||||
|
||||
def to_python(self, value):
|
||||
return int(value)
|
||||
|
||||
def to_url(self, value):
|
||||
return str(value).zfill(2)
|
||||
|
||||
|
||||
class BooleanStringConverter:
|
||||
"""
|
||||
Converter whose regex match either True or False
|
||||
"""
|
||||
|
||||
regex = r"(True)|(False)"
|
||||
|
||||
def to_python(self, value):
|
||||
return str(value) == "True"
|
||||
|
||||
def to_url(self, value):
|
||||
return str(value)
|
Reference in New Issue
Block a user