From 13d4acddf63858e59c798837cf4c1f2d29945dd7 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 22 Mar 2024 13:10:52 +0100 Subject: ✨ Debug mode for imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 08e7a49b4..c88342782 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 +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 @@ -2557,6 +2558,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) -- cgit v1.2.3