From 112f3746cdaa09c1d7492954e82c2c7158ddae3d Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Fri, 15 Jan 2016 13:00:59 +0200 Subject: bitbake: toastergui: serialise decimals correctly 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. (Bitbake rev: fa6229d4edf5904ccaa9dc323d0ab2318d1ef314) Signed-off-by: Elliot Smith Signed-off-by: Ed Bartosh Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index fbae36c69c..3e8a66bfb1 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/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): -- cgit v1.2.3-54-g00ecf