aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui/tables.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-03 12:36:30 +0100
committerAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-10 15:31:12 +0100
commit1778dac9fd39dae75c55bf2cf836cdd488dbc265 (patch)
tree99765f72b1e3e131818a9f10b474201bcd1d9f7e /lib/toaster/toastergui/tables.py
parent7a6eb36b82c5f2e342777e479d9c401ded42453d (diff)
downloadbitbake-1778dac9fd39dae75c55bf2cf836cdd488dbc265.tar.gz
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. Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Diffstat (limited to 'lib/toaster/toastergui/tables.py')
-rw-r--r--lib/toaster/toastergui/tables.py84
1 files changed, 56 insertions, 28 deletions
diff --git a/lib/toaster/toastergui/tables.py b/lib/toaster/toastergui/tables.py
index 9a93ff9aa..b75e56524 100644
--- a/lib/toaster/toastergui/tables.py
+++ b/lib/toaster/toastergui/tables.py
@@ -19,7 +19,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-from widgets import ToasterTable
+from toastergui.widgets import ToasterTable
from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
from django.db.models import Q, Max
from django.conf.urls import url
@@ -29,9 +29,19 @@ class LayersTable(ToasterTable):
"""Table of layers in Toaster"""
def __init__(self, *args, **kwargs):
- ToasterTable.__init__(self)
+ super(LayersTable, self).__init__(*args, **kwargs)
self.default_orderby = "layer__name"
+ def get_context_data(self, **kwargs):
+ context = super(LayersTable, self).get_context_data(**kwargs)
+
+ context['project'] = Project.objects.get(pk=kwargs['pid'])
+
+ context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
+
+ return context
+
+
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
compatible_layers = prj.compatible_layerversions()
@@ -132,14 +142,31 @@ class LayersTable(ToasterTable):
static_data_name="add-del-layers",
static_data_template='{% include "layer_btn.html" %}')
+class LayerDetails(TemplateView):
+ def get_context_data(self, **kwargs):
+ context = super(LayerDetails, self).get_context_data(**kwargs)
+
+ context['project'] = Project.objects.get(pk=kwargs['pid'])
+ context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
+ context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
+
+ return context
+
class MachinesTable(ToasterTable):
"""Table of Machines in Toaster"""
def __init__(self, *args, **kwargs):
- ToasterTable.__init__(self)
+ super(MachinesTable, self).__init__(*args, **kwargs)
self.empty_state = "No machines maybe you need to do a build?"
self.default_orderby = "name"
+ def get_context_data(self, **kwargs):
+ context = super(MachinesTable, self).get_context_data(**kwargs)
+ context['project'] = Project.objects.get(pk=kwargs['pid'])
+ context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
+ return context
+
+
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
compatible_layers = prj.compatible_layerversions()
@@ -191,7 +218,13 @@ class LayerMachinesTable(MachinesTable):
""" Smaller version of the Machines table for use in layer details """
def __init__(self, *args, **kwargs):
- MachinesTable.__init__(self)
+ super(LayerMachinesTable, self).__init__(*args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ context = super(LayerMachinesTable, self).get_context_data(**kwargs)
+ context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
+ return context
+
def setup_queryset(self, *args, **kwargs):
MachinesTable.setup_queryset(self, *args, **kwargs)
@@ -219,10 +252,20 @@ class RecipesTable(ToasterTable):
"""Table of Recipes in Toaster"""
def __init__(self, *args, **kwargs):
- ToasterTable.__init__(self)
+ super(RecipesTable, self).__init__(*args, **kwargs)
self.empty_state = "Toaster has no recipe information. To generate recipe information you can configure a layer source then run a build."
self.default_orderby = "name"
+ def get_context_data(self, **kwargs):
+ context = super(RecipesTable, self).get_context_data(**kwargs)
+
+ context['project'] = Project.objects.get(pk=kwargs['pid'])
+
+ context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
+
+ return context
+
+
def setup_queryset(self, *args, **kwargs):
prj = Project.objects.get(pk = kwargs['pid'])
@@ -293,10 +336,16 @@ class RecipesTable(ToasterTable):
static_data_template='{% include "recipe_btn.html" %}')
class LayerRecipesTable(RecipesTable):
- """ Smaller version of the Machines table for use in layer details """
+ """ Smaller version of the Recipes table for use in layer details """
def __init__(self, *args, **kwargs):
- RecipesTable.__init__(self)
+ super(LayerRecipesTable, self).__init__(*args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ context = super(LayerRecipesTable, self).get_context_data(**kwargs)
+ context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
+ return context
+
def setup_queryset(self, *args, **kwargs):
RecipesTable.setup_queryset(self, *args, **kwargs)
@@ -320,24 +369,3 @@ class LayerRecipesTable(RecipesTable):
self.add_column(title="Build recipe",
static_data_name="add-del-layers",
static_data_template=build_recipe_template)
-
-
-
-# This needs to be staticaly defined here as django reads the url patterns
-# on start up
-urlpatterns = (
- url(r'^machines/(?P<cmd>\w+)*', MachinesTable.as_view(),
- name=MachinesTable.__name__.lower()),
- url(r'^layers/(?P<cmd>\w+)*', LayersTable.as_view(),
- name=LayersTable.__name__.lower()),
- url(r'^recipes/(?P<cmd>\w+)*', RecipesTable.as_view(),
- name=RecipesTable.__name__.lower()),
-
- # layer details tables
- url(r'^layer/(?P<layerid>\d+)/recipes/(?P<cmd>\w+)*',
- LayerRecipesTable.as_view(),
- name=LayerRecipesTable.__name__.lower()),
- url(r'^layer/(?P<layerid>\d+)/machines/(?P<cmd>\w+)*',
- LayerMachinesTable.as_view(),
- name=LayerMachinesTable.__name__.lower()),
-)