summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/widgets.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-03 12:36:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-12 00:01:47 +0100
commitd9341d1a774ccea25e64583f9adc61b163fb1f95 (patch)
treea2989f7885d4b1a3acce138cfdd93b864fd81832 /bitbake/lib/toaster/toastergui/widgets.py
parent751e9182ac7f37506c3d85cade00ef6f3986eb7a (diff)
downloadpoky-d9341d1a774ccea25e64583f9adc61b163fb1f95.tar.gz
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 <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/widgets.py')
-rw-r--r--bitbake/lib/toaster/toastergui/widgets.py47
1 files changed, 19 insertions, 28 deletions
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
32from django.core.exceptions import FieldError 32from django.core.exceptions import FieldError
33from django.conf.urls import url, patterns 33from django.conf.urls import url, patterns
34 34
35import urls
36import types 35import types
37import json 36import json
38import collections 37import collections
39import operator 38import operator
40 39
41 40
42class ToasterTemplateView(TemplateView): 41class ToasterTable(TemplateView):
43 def get_context_data(self, **kwargs): 42 def __init__(self, *args, **kwargs):
44 context = super(ToasterTemplateView, self).get_context_data(**kwargs) 43 super(ToasterTable, self).__init__()
45 if 'pid' in kwargs: 44 if 'template_name' in kwargs:
46 context['project'] = Project.objects.get(pk=kwargs['pid']) 45 self.template_name = kwargs['template_name']
47
48 context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
49
50 if 'layerid' in kwargs:
51 context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
52
53 return context
54
55
56class ToasterTable(View):
57 def __init__(self):
58 self.title = None 46 self.title = None
59 self.queryset = None 47 self.queryset = None
60 self.columns = [] 48 self.columns = []
@@ -66,20 +54,23 @@ class ToasterTable(View):
66 self.default_orderby = "" 54 self.default_orderby = ""
67 55
68 def get(self, request, *args, **kwargs): 56 def get(self, request, *args, **kwargs):
69 self.setup_queryset(*args, **kwargs) 57 if request.GET.get('format', None) == 'json':
70 58
71 # Put the project id into the context for the static_data_template 59 self.setup_queryset(*args, **kwargs)
72 if 'pid' in kwargs: 60 # Put the project id into the context for the static_data_template
73 self.static_context_extra['pid'] = kwargs['pid'] 61 if 'pid' in kwargs:
62 self.static_context_extra['pid'] = kwargs['pid']
74 63
75 cmd = kwargs['cmd'] 64 cmd = request.GET.get('cmd', None)
76 if cmd and 'filterinfo' in cmd: 65 if cmd and 'filterinfo' in cmd:
77 data = self.get_filter_info(request) 66 data = self.get_filter_info(request)
78 else: 67 else:
79 # If no cmd is specified we give you the table data 68 # If no cmd is specified we give you the table data
80 data = self.get_data(request, **kwargs) 69 data = self.get_data(request, **kwargs)
70
71 return HttpResponse(data, content_type="application/json")
81 72
82 return HttpResponse(data, content_type="application/json") 73 return super(ToasterTable, self).get(request, *args, **kwargs)
83 74
84 def get_filter_info(self, request): 75 def get_filter_info(self, request):
85 data = None 76 data = None