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 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  <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 @@ -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)  | 
