From efbffe3c298d57af34324639f2208e35735758a9 Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Mon, 18 Jan 2016 14:23:55 +0000 Subject: bitbake: toaster: move recent builds query to model The progress updater for the recent builds section makes a JSON call to the project view URL to get progress for each build. However, conversion of the builds pages to ToasterTable broke this, as the JSON response no longer contained the data necessary to populate the progress bars. Move the recent builds query to the Build model, so that it is accessible to the ToasterTables using it ("project builds" and "all builds"), as well as to the "project" view. Modify the code in the recent builds template to use the slightly different objects returned by the recent builds query on Build. (Bitbake rev: 5189252635ddc7b90c9a43aaed9f196c31e1dcad) Signed-off-by: Elliot Smith Signed-off-by: brian avery Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/tables.py | 33 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'bitbake/lib/toaster/toastergui/tables.py') diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index ba2726d070..7fb3f8605e 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -28,7 +28,6 @@ from django.conf.urls import url from django.core.urlresolvers import reverse, resolve from django.http import HttpResponse from django.views.generic import TemplateView -import itertools from toastergui.tablefilter import TableFilter from toastergui.tablefilter import TableFilterActionToggle @@ -1060,17 +1059,9 @@ class BuildsTable(ToasterTable): def get_context_data(self, **kwargs): context = super(BuildsTable, self).get_context_data(**kwargs) - # for the latest builds section - builds = self.get_builds() + # should be set in subclasses + context['mru'] = [] - finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) - - latest_builds = itertools.chain( - builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), - builds.filter(finished_criteria).order_by("-completed_on")[:3] - ) - - context['mru'] = list(latest_builds) context['mrb_type'] = self.mrb_type return context @@ -1481,6 +1472,12 @@ class AllBuildsTable(BuildsTable): static_data_name='project', static_data_template=project_template) + def get_context_data(self, **kwargs): + """ Get all builds for the recent builds area """ + context = super(AllBuildsTable, self).get_context_data(**kwargs) + context['mru'] = Build.get_recent() + return context + class ProjectBuildsTable(BuildsTable): """ Builds page for a single project; a BuildsTable, with the queryset @@ -1521,18 +1518,16 @@ class ProjectBuildsTable(BuildsTable): def get_context_data(self, **kwargs): """ + Get recent builds for this project, and the project itself + NOTE: self.project_id must be set before calling super(), as it's used in get_context_data() """ self.project_id = kwargs['pid'] - context = super(ProjectBuildsTable, self).get_context_data(**kwargs) - context['project'] = Project.objects.get(pk=self.project_id) - - return context - - def get_builds(self): - """ override: only return builds for the relevant project """ project = Project.objects.get(pk=self.project_id) - return Build.objects.filter(project=project) + context['mru'] = Build.get_recent(project) + context['project'] = project + + return context -- cgit v1.2.3-54-g00ecf