From d9341d1a774ccea25e64583f9adc61b163fb1f95 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Wed, 3 Jun 2015 12:36:30 +0100 Subject: bitbake: toaster: toastertables REST refactoring This patch refactors the ToasterTables to bring them in line with REST principles - - all table pages now support the "format=json" GET parameter that returns the data in JSON format - the tables themselves This cleans up the URL namespace by aleviating the need to have two URLS for each table (one for the template and one for the data loading), and fixes minor things in the ToasterTable implementation. (Bitbake rev: 1778dac9fd39dae75c55bf2cf836cdd488dbc265) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/widgets.py | 47 +++++++++++++------------------ 1 file changed, 19 insertions(+), 28 deletions(-) (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 8cf6e1bc2d..4347a3f081 100644 --- a/bitbake/lib/toaster/toastergui/widgets.py +++ b/bitbake/lib/toaster/toastergui/widgets.py @@ -32,29 +32,17 @@ from django.core.serializers.json import DjangoJSONEncoder from django.core.exceptions import FieldError from django.conf.urls import url, patterns -import urls import types import json import collections import operator -class ToasterTemplateView(TemplateView): - def get_context_data(self, **kwargs): - context = super(ToasterTemplateView, self).get_context_data(**kwargs) - if 'pid' in kwargs: - context['project'] = Project.objects.get(pk=kwargs['pid']) - - context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) - - if 'layerid' in kwargs: - context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid']) - - return context - - -class ToasterTable(View): - def __init__(self): +class ToasterTable(TemplateView): + def __init__(self, *args, **kwargs): + super(ToasterTable, self).__init__() + if 'template_name' in kwargs: + self.template_name = kwargs['template_name'] self.title = None self.queryset = None self.columns = [] @@ -66,20 +54,23 @@ class ToasterTable(View): self.default_orderby = "" def get(self, request, *args, **kwargs): - self.setup_queryset(*args, **kwargs) + if request.GET.get('format', None) == 'json': - # Put the project id into the context for the static_data_template - if 'pid' in kwargs: - self.static_context_extra['pid'] = kwargs['pid'] + self.setup_queryset(*args, **kwargs) + # Put the project id into the context for the static_data_template + if 'pid' in kwargs: + self.static_context_extra['pid'] = kwargs['pid'] - cmd = kwargs['cmd'] - if cmd and 'filterinfo' in cmd: - data = self.get_filter_info(request) - else: - # If no cmd is specified we give you the table data - data = self.get_data(request, **kwargs) + cmd = request.GET.get('cmd', None) + if cmd and 'filterinfo' in cmd: + data = self.get_filter_info(request) + else: + # If no cmd is specified we give you the table data + data = self.get_data(request, **kwargs) + + return HttpResponse(data, content_type="application/json") - return HttpResponse(data, content_type="application/json") + return super(ToasterTable, self).get(request, *args, **kwargs) def get_filter_info(self, request): data = None -- cgit v1.2.3-54-g00ecf