# HG changeset patch # User Goffi # Date 1592574357 -7200 # Node ID 3af0909629a200d911c8d893ca3a1940a58e3165 # Parent 04a7d77ed86f4eb83f6d1273388c0eaac1020cbe common (template): better json dumping: default method is set for json dumping (the `tojson` filter), if the object has a `json` attribute, it will be called, otherwise it is replaced by None, this avoids crash when rendering the template. diff -r 04a7d77ed86f -r 3af0909629a2 sat/tools/common/template.py --- a/sat/tools/common/template.py Fri Jun 19 15:39:32 2020 +0200 +++ b/sat/tools/common/template.py Fri Jun 19 15:45:57 2020 +0200 @@ -451,6 +451,11 @@ # policies self.env.policies["ext.i18n.trimmed"] = True + self.env.policies["json.dumps_kwargs"] = { + "sort_keys": True, + # if object can't be serialised, we use None + "default": lambda o: o.json() if hasattr(o, "json") else None + } def getFrontURL(self, template_data, path=None): """Give front URL (i.e. URL seen by end-user) of a path