summaryrefslogtreecommitdiff
path: root/ishtar_common/urls_converters.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-11-28 17:58:55 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-19 14:45:56 +0100
commitd0760b4da854e1dadb4ff130468a4c6d185b1abc (patch)
tree464aab890c5d8ea8b51f6ad3558446b3c8018036 /ishtar_common/urls_converters.py
parentf10b03c55ece933e4277cdf1e7d4acfba9fdd7ed (diff)
downloadIshtar-d0760b4da854e1dadb4ff130468a4c6d185b1abc.tar.bz2
Ishtar-d0760b4da854e1dadb4ff130468a4c6d185b1abc.zip
✨ exhibition: forms/sheets
Diffstat (limited to 'ishtar_common/urls_converters.py')
-rw-r--r--ishtar_common/urls_converters.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/ishtar_common/urls_converters.py b/ishtar_common/urls_converters.py
index 9395af648..b5185fd1f 100644
--- a/ishtar_common/urls_converters.py
+++ b/ishtar_common/urls_converters.py
@@ -17,6 +17,8 @@
# See the file COPYING for details.
+from datetime import datetime
+
class UnderscoreSlug:
regex = '[_0-9a-z]+'
@@ -27,3 +29,15 @@ class UnderscoreSlug:
def to_url(self, value):
return str(value)
+
+class DateTimeConverter:
+ regex = r"\d{4}-\d{1,2}-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}\.\d{1,6}"
+ date_format = '%Y-%m-%dT%H:%M:%S.%f'
+
+ def to_python(self, value):
+ return datetime.strptime(value, self.date_format)
+
+ def to_url(self, value):
+ if isinstance(value, datetime):
+ return value.strftime(self.date_format)
+ return value