summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/tables.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/tables.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/tables.py')
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py84
1 files changed, 56 insertions, 28 deletions
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index 9a93ff9aad..b75e565246 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -19,7 +19,7 @@
19# with this program; if not, write to the Free Software Foundation, Inc., 19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 21
22from widgets import ToasterTable 22from toastergui.widgets import ToasterTable
23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project 23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
24from django.db.models import Q, Max 24from django.db.models import Q, Max
25from django.conf.urls import url 25from django.conf.urls import url
@@ -29,9 +29,19 @@ class LayersTable(ToasterTable):
29 """Table of layers in Toaster""" 29 """Table of layers in Toaster"""
30 30
31 def __init__(self, *args, **kwargs): 31 def __init__(self, *args, **kwargs):
32 ToasterTable.__init__(self) 32 super(LayersTable, self).__init__(*args, **kwargs)
33 self.default_orderby = "layer__name" 33 self.default_orderby = "layer__name"
34 34
35 def get_context_data(self, **kwargs):
36 context = super(LayersTable, self).get_context_data(**kwargs)
37
38 context['project'] = Project.objects.get(pk=kwargs['pid'])
39
40 context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
41
42 return context
43
44
35 def setup_queryset(self, *args, **kwargs): 45 def setup_queryset(self, *args, **kwargs):
36 prj = Project.objects.get(pk = kwargs['pid']) 46 prj = Project.objects.get(pk = kwargs['pid'])
37 compatible_layers = prj.compatible_layerversions() 47 compatible_layers = prj.compatible_layerversions()
@@ -132,14 +142,31 @@ class LayersTable(ToasterTable):
132 static_data_name="add-del-layers", 142 static_data_name="add-del-layers",
133 static_data_template='{% include "layer_btn.html" %}') 143 static_data_template='{% include "layer_btn.html" %}')
134 144
145class LayerDetails(TemplateView):
146 def get_context_data(self, **kwargs):
147 context = super(LayerDetails, self).get_context_data(**kwargs)
148
149 context['project'] = Project.objects.get(pk=kwargs['pid'])
150 context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
151 context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
152
153 return context
154
135class MachinesTable(ToasterTable): 155class MachinesTable(ToasterTable):
136 """Table of Machines in Toaster""" 156 """Table of Machines in Toaster"""
137 157
138 def __init__(self, *args, **kwargs): 158 def __init__(self, *args, **kwargs):
139 ToasterTable.__init__(self) 159 super(MachinesTable, self).__init__(*args, **kwargs)
140 self.empty_state = "No machines maybe you need to do a build?" 160 self.empty_state = "No machines maybe you need to do a build?"
141 self.default_orderby = "name" 161 self.default_orderby = "name"
142 162
163 def get_context_data(self, **kwargs):
164 context = super(MachinesTable, self).get_context_data(**kwargs)
165 context['project'] = Project.objects.get(pk=kwargs['pid'])
166 context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
167 return context
168
169
143 def setup_queryset(self, *args, **kwargs): 170 def setup_queryset(self, *args, **kwargs):
144 prj = Project.objects.get(pk = kwargs['pid']) 171 prj = Project.objects.get(pk = kwargs['pid'])
145 compatible_layers = prj.compatible_layerversions() 172 compatible_layers = prj.compatible_layerversions()
@@ -191,7 +218,13 @@ class LayerMachinesTable(MachinesTable):
191 """ Smaller version of the Machines table for use in layer details """ 218 """ Smaller version of the Machines table for use in layer details """
192 219
193 def __init__(self, *args, **kwargs): 220 def __init__(self, *args, **kwargs):
194 MachinesTable.__init__(self) 221 super(LayerMachinesTable, self).__init__(*args, **kwargs)
222
223 def get_context_data(self, **kwargs):
224 context = super(LayerMachinesTable, self).get_context_data(**kwargs)
225 context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
226 return context
227
195 228
196 def setup_queryset(self, *args, **kwargs): 229 def setup_queryset(self, *args, **kwargs):
197 MachinesTable.setup_queryset(self, *args, **kwargs) 230 MachinesTable.setup_queryset(self, *args, **kwargs)
@@ -219,10 +252,20 @@ class RecipesTable(ToasterTable):
219 """Table of Recipes in Toaster""" 252 """Table of Recipes in Toaster"""
220 253
221 def __init__(self, *args, **kwargs): 254 def __init__(self, *args, **kwargs):
222 ToasterTable.__init__(self) 255 super(RecipesTable, self).__init__(*args, **kwargs)
223 self.empty_state = "Toaster has no recipe information. To generate recipe information you can configure a layer source then run a build." 256 self.empty_state = "Toaster has no recipe information. To generate recipe information you can configure a layer source then run a build."
224 self.default_orderby = "name" 257 self.default_orderby = "name"
225 258
259 def get_context_data(self, **kwargs):
260 context = super(RecipesTable, self).get_context_data(**kwargs)
261
262 context['project'] = Project.objects.get(pk=kwargs['pid'])
263
264 context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
265
266 return context
267
268
226 def setup_queryset(self, *args, **kwargs): 269 def setup_queryset(self, *args, **kwargs):
227 prj = Project.objects.get(pk = kwargs['pid']) 270 prj = Project.objects.get(pk = kwargs['pid'])
228 271
@@ -293,10 +336,16 @@ class RecipesTable(ToasterTable):
293 static_data_template='{% include "recipe_btn.html" %}') 336 static_data_template='{% include "recipe_btn.html" %}')
294 337
295class LayerRecipesTable(RecipesTable): 338class LayerRecipesTable(RecipesTable):
296 """ Smaller version of the Machines table for use in layer details """ 339 """ Smaller version of the Recipes table for use in layer details """
297 340
298 def __init__(self, *args, **kwargs): 341 def __init__(self, *args, **kwargs):
299 RecipesTable.__init__(self) 342 super(LayerRecipesTable, self).__init__(*args, **kwargs)
343
344 def get_context_data(self, **kwargs):
345 context = super(LayerRecipesTable, self).get_context_data(**kwargs)
346 context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
347 return context
348
300 349
301 def setup_queryset(self, *args, **kwargs): 350 def setup_queryset(self, *args, **kwargs):
302 RecipesTable.setup_queryset(self, *args, **kwargs) 351 RecipesTable.setup_queryset(self, *args, **kwargs)
@@ -320,24 +369,3 @@ class LayerRecipesTable(RecipesTable):
320 self.add_column(title="Build recipe", 369 self.add_column(title="Build recipe",
321 static_data_name="add-del-layers", 370 static_data_name="add-del-layers",
322 static_data_template=build_recipe_template) 371 static_data_template=build_recipe_template)
323
324
325
326# This needs to be staticaly defined here as django reads the url patterns
327# on start up
328urlpatterns = (
329 url(r'^machines/(?P<cmd>\w+)*', MachinesTable.as_view(),
330 name=MachinesTable.__name__.lower()),
331 url(r'^layers/(?P<cmd>\w+)*', LayersTable.as_view(),
332 name=LayersTable.__name__.lower()),
333 url(r'^recipes/(?P<cmd>\w+)*', RecipesTable.as_view(),
334 name=RecipesTable.__name__.lower()),
335
336 # layer details tables
337 url(r'^layer/(?P<layerid>\d+)/recipes/(?P<cmd>\w+)*',
338 LayerRecipesTable.as_view(),
339 name=LayerRecipesTable.__name__.lower()),
340 url(r'^layer/(?P<layerid>\d+)/machines/(?P<cmd>\w+)*',
341 LayerMachinesTable.as_view(),
342 name=LayerMachinesTable.__name__.lower()),
343)