diff options
| author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2015-06-08 11:12:47 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-06-12 00:01:48 +0100 |
| commit | 7c2b86625b75f0c3c5447d240175558be1e37919 (patch) | |
| tree | 103e2efd1fdb6de3c198ff475fe9380302e2d6eb | |
| parent | 51ae1de5b75b6f831b46433b2e36c6112d1a0c59 (diff) | |
| download | poky-7c2b86625b75f0c3c5447d240175558be1e37919.tar.gz | |
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 <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/lib/toaster/toastergui/tables.py | 12 | ||||
| -rw-r--r-- | bitbake/lib/toaster/toastergui/widgets.py | 26 |
2 files changed, 36 insertions, 2 deletions
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index e540b91499..e03aa768c9 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 | ||
| 22 | from toastergui.widgets import ToasterTable | 22 | from toastergui.widgets import ToasterTable, ToasterTemplateView |
| 23 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project | 23 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project |
| 24 | from django.db.models import Q, Max | 24 | from django.db.models import Q, Max |
| 25 | from django.conf.urls import url | 25 | from django.conf.urls import url |
| @@ -142,16 +142,24 @@ class LayersTable(ToasterTable): | |||
| 142 | static_data_name="add-del-layers", | 142 | static_data_name="add-del-layers", |
| 143 | static_data_template='{% include "layer_btn.html" %}') | 143 | static_data_template='{% include "layer_btn.html" %}') |
| 144 | 144 | ||
| 145 | class LayerDetails(TemplateView): | 145 | |
| 146 | |||
| 147 | class LayerDetails(ToasterTemplateView): | ||
| 146 | def get_context_data(self, **kwargs): | 148 | def get_context_data(self, **kwargs): |
| 147 | context = super(LayerDetails, self).get_context_data(**kwargs) | 149 | context = super(LayerDetails, self).get_context_data(**kwargs) |
| 150 | from toastergui.views import _lv_to_dict | ||
| 148 | 151 | ||
| 149 | context['project'] = Project.objects.get(pk=kwargs['pid']) | 152 | context['project'] = Project.objects.get(pk=kwargs['pid']) |
| 150 | context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid']) | 153 | context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid']) |
| 154 | context['layerdict'] = _lv_to_dict(context['project'], context['layerversion']) | ||
| 155 | context['layerdeps'] = {"list": [x.depends_on.get_equivalents_wpriority(context['project'])[0] for x in context['layerversion'].dependencies.all()]} | ||
| 151 | context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) | 156 | context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project'])) |
| 152 | 157 | ||
| 158 | self.context_entries = ['project', 'layerversion', 'projectlayers', 'layerdict', 'layerdeps'] | ||
| 159 | |||
| 153 | return context | 160 | return context |
| 154 | 161 | ||
| 162 | |||
| 155 | class MachinesTable(ToasterTable): | 163 | class MachinesTable(ToasterTable): |
| 156 | """Table of Machines in Toaster""" | 164 | """Table of Machines in Toaster""" |
| 157 | 165 | ||
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): | |||
| 325 | cache.set(cache_name, data, 60*30) | 325 | cache.set(cache_name, data, 60*30) |
| 326 | 326 | ||
| 327 | return data | 327 | return data |
| 328 | |||
| 329 | |||
| 330 | class ToasterTemplateView(TemplateView): | ||
| 331 | # renders a instance in a template, or returns the context as json | ||
| 332 | # the class-equivalent of the _template_renderer decorator for views | ||
| 333 | |||
| 334 | |||
| 335 | def get(self, *args, **kwargs): | ||
| 336 | if self.request.GET.get('format', None) == 'json': | ||
| 337 | from django.core.urlresolvers import reverse | ||
| 338 | from django.shortcuts import HttpResponse | ||
| 339 | from views import objtojson | ||
| 340 | from toastergui.templatetags.projecttags import json as jsonfilter | ||
| 341 | |||
| 342 | context = self.get_context_data(**kwargs) | ||
| 343 | |||
| 344 | for x in context.keys(): | ||
| 345 | if x not in self.context_entries: | ||
| 346 | del context[x] | ||
| 347 | |||
| 348 | context["error"] = "ok" | ||
| 349 | |||
| 350 | return HttpResponse(jsonfilter(context, default=objtojson ), | ||
| 351 | content_type = "application/json; charset=utf-8") | ||
| 352 | |||
| 353 | return super(ToasterTemplateView, self).get(*args, **kwargs) | ||
