[bitbake-devel] [PATCH 16/23] toaster: toastergui: serialise decimals correctly
Ed Bartosh
ed.bartosh at linux.intel.com
Fri Jan 15 11:00:59 UTC 2016
From: Elliot Smith <elliot.smith at intel.com>
The conversion of some ToasterTable Build object querysets to
JSON caused a serialisation error. This is because one of the
fields in the queryset was of type decimal.Decimal, and our
serialiser didn't know what to do with it.
Add a clause to check for decimal fields and serialise them
so that correct JSON can be generated.
Signed-off-by: Elliot Smith <elliot.smith at intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
---
lib/toaster/toastergui/views.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index fbae36c..3e8a66b 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -43,6 +43,7 @@ from django.utils.html import escape
from datetime import timedelta, datetime
from django.utils import formats
from toastergui.templatetags.projecttags import json as jsonfilter
+from decimal import Decimal
import json
from os.path import dirname
from functools import wraps
@@ -145,6 +146,8 @@ def objtojson(obj):
return obj.total_seconds()
elif isinstance(obj, QuerySet) or isinstance(obj, set):
return list(obj)
+ elif isinstance(obj, Decimal):
+ return str(obj)
elif type(obj).__name__ == "RelatedManager":
return [x.pk for x in obj.all()]
elif hasattr( obj, '__dict__') and isinstance(obj, Model):
--
2.1.4
More information about the bitbake-devel
mailing list