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>
This commit is contained in:
parent
51ae1de5b7
commit
7c2b86625b
|
@ -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 toastergui.widgets import ToasterTable
|
||||
from toastergui.widgets import ToasterTable, ToasterTemplateView
|
||||
from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
|
||||
from django.db.models import Q, Max
|
||||
from django.conf.urls import url
|
||||
|
@ -142,16 +142,24 @@ class LayersTable(ToasterTable):
|
|||
static_data_name="add-del-layers",
|
||||
static_data_template='{% include "layer_btn.html" %}')
|
||||
|
||||
class LayerDetails(TemplateView):
|
||||
|
||||
|
||||
class LayerDetails(ToasterTemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(LayerDetails, self).get_context_data(**kwargs)
|
||||
from toastergui.views import _lv_to_dict
|
||||
|
||||
context['project'] = Project.objects.get(pk=kwargs['pid'])
|
||||
context['layerversion'] = Layer_Version.objects.get(pk=kwargs['layerid'])
|
||||
context['layerdict'] = _lv_to_dict(context['project'], context['layerversion'])
|
||||
context['layerdeps'] = {"list": [x.depends_on.get_equivalents_wpriority(context['project'])[0] for x in context['layerversion'].dependencies.all()]}
|
||||
context['projectlayers'] = map(lambda prjlayer: prjlayer.layercommit.id, ProjectLayer.objects.filter(project=context['project']))
|
||||
|
||||
self.context_entries = ['project', 'layerversion', 'projectlayers', 'layerdict', 'layerdeps']
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class MachinesTable(ToasterTable):
|
||||
"""Table of Machines in Toaster"""
|
||||
|
||||
|
|
|
@ -325,3 +325,29 @@ class ToasterTable(TemplateView):
|
|||
cache.set(cache_name, data, 60*30)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class ToasterTemplateView(TemplateView):
|
||||
# renders a instance in a template, or returns the context as json
|
||||
# the class-equivalent of the _template_renderer decorator for views
|
||||
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
if self.request.GET.get('format', None) == 'json':
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import HttpResponse
|
||||
from views import objtojson
|
||||
from toastergui.templatetags.projecttags import json as jsonfilter
|
||||
|
||||
context = self.get_context_data(**kwargs)
|
||||
|
||||
for x in context.keys():
|
||||
if x not in self.context_entries:
|
||||
del context[x]
|
||||
|
||||
context["error"] = "ok"
|
||||
|
||||
return HttpResponse(jsonfilter(context, default=objtojson ),
|
||||
content_type = "application/json; charset=utf-8")
|
||||
|
||||
return super(ToasterTemplateView, self).get(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue