diff options
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 13 |
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) |