From 7c2b86625b75f0c3c5447d240175558be1e37919 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Mon, 8 Jun 2015 11:12:47 +0100 Subject: bitbake: toaster: add class template view for single-object pages Adding ToasterTemplateView as prototype for all class-based views that display single objects; equivalent to ToasterTable for object lists. (Bitbake rev: d3edea773000a663f5883e04f477d853bff64cf6) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/widgets.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'bitbake/lib/toaster/toastergui/widgets.py') diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py index 3d3c1d10df..8bc3d7f160 100644 --- a/bitbake/lib/toaster/toastergui/widgets.py +++ b/bitbake/lib/toaster/toastergui/widgets.py @@ -325,3 +325,29 @@ class ToasterTable(TemplateView): cache.set(cache_name, data, 60*30) return data + + +class ToasterTemplateView(TemplateView): + # renders a instance in a template, or returns the context as json + # the class-equivalent of the _template_renderer decorator for views + + + def get(self, *args, **kwargs): + if self.request.GET.get('format', None) == 'json': + from django.core.urlresolvers import reverse + from django.shortcuts import HttpResponse + from views import objtojson + from toastergui.templatetags.projecttags import json as jsonfilter + + context = self.get_context_data(**kwargs) + + for x in context.keys(): + if x not in self.context_entries: + del context[x] + + context["error"] = "ok" + + return HttpResponse(jsonfilter(context, default=objtojson ), + content_type = "application/json; charset=utf-8") + + return super(ToasterTemplateView, self).get(*args, **kwargs) -- cgit v1.2.3-54-g00ecf