summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/views.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-08 11:01:43 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-12 00:01:48 +0100
commit58600cf8e76f270969ded6ec63ac0908f39dae09 (patch)
treef87738a1ce5857a576c236f43b85b3ec83089c88 /bitbake/lib/toaster/toastergui/views.py
parent4a2a057130e877eae96d726bc86c6b9f48ed1ca3 (diff)
downloadpoky-58600cf8e76f270969ded6ec63ac0908f39dae09.tar.gz
bitbake: toaster: toaster table add raw data
We add in a JSON response both the raw data and the rendered version for display. The rendered fields start with "static:" to mark a different "namespace". The toaster.js is updated to always display the "static:" version of a field, if it exists (and ignore the raw data unless the static rendering is missing). (Bitbake rev: 928ee3fd4b52ea14b7eb704f1f27351362a9d27a) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/views.py')
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index 91c4fa2543..280159ad2c 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -87,6 +87,35 @@ def _project_recent_build_list(prj):
87 list(prj.buildrequest_set.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3])) 87 list(prj.buildrequest_set.filter(state__in=[BuildRequest.REQ_COMPLETED, BuildRequest.REQ_FAILED]).order_by("-pk")[:3]))
88 88
89 89
90
91def objtojson(obj):
92 from django.db.models.query import QuerySet
93 from django.db.models import Model, IntegerField
94 from django.db.models.fields.related import ForeignKey
95
96 if isinstance(obj, datetime):
97 return obj.isoformat()
98 elif isinstance(obj, timedelta):
99 return obj.total_seconds()
100 elif isinstance(obj, QuerySet) or isinstance(obj, set):
101 return list(obj)
102 elif type(obj).__name__ == "RelatedManager":
103 return [x.pk for x in obj.all()]
104 elif hasattr( obj, '__dict__') and isinstance(obj, Model):
105 d = obj.__dict__
106 nd = dict(d)
107 for di in d.keys():
108 if di.startswith("_"):
109 del nd[di]
110 elif isinstance(d[di], Model):
111 nd[di] = d[di].pk
112 elif isinstance(d[di], int) and hasattr(obj, "get_%s_display" % di):
113 nd[di] = getattr(obj, "get_%s_display" % di)()
114 return nd
115 else:
116 raise TypeError("Unserializable object %s (%s) of type %s" % ( obj, dir(obj), type(obj)))
117
118
90def _template_renderer(template): 119def _template_renderer(template):
91 def func_wrapper(view): 120 def func_wrapper(view):
92 def returned_wrapper(request, *args, **kwargs): 121 def returned_wrapper(request, *args, **kwargs):
@@ -127,7 +156,7 @@ def _template_renderer(template):
127 else: 156 else:
128 raise TypeError("Unserializable object %s of type %s" % ( obj, type(obj))) 157 raise TypeError("Unserializable object %s of type %s" % ( obj, type(obj)))
129 158
130 return HttpResponse(jsonfilter(context, default=_objtojson ), 159 return HttpResponse(jsonfilter(context, default=objtojson ),
131 content_type = "application/json; charset=utf-8") 160 content_type = "application/json; charset=utf-8")
132 else: 161 else:
133 return render(request, template, context) 162 return render(request, template, context)