summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-03-22 13:10:52 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-03-22 13:23:14 +0100
commita4b5f36facba9d2d8685c796acda7d4c35e3c51e (patch)
tree594e31ccbf84130a79565b70b54cbe5318e59d80 /ishtar_common/utils.py
parentaf5f58021b975d2bd4081ac80cc9976f096d3a16 (diff)
downloadIshtar-a4b5f36facba9d2d8685c796acda7d4c35e3c51e.tar.bz2
Ishtar-a4b5f36facba9d2d8685c796acda7d4c35e3c51e.zip
✨ Debug mode for imports
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index f1c899a69..1ebb87565 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+import json
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -2482,6 +2483,18 @@ def human_date(value):
return value.strftime(settings.DATE_FORMAT)
+class StrJSONEncoder(json.JSONEncoder):
+ def default(self, o):
+ try:
+ return super().default(o)
+ except TypeError:
+ s = f"<{o.__class__.__name__}> "
+ if hasattr(o, "pk"):
+ s += f"[{o.pk}] "
+ s += str(o)
+ return s
+
+
class IshtarFileSystemStorage(FileSystemStorage):
def exists(self, name):
path_name = self.path(name)