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/orm/models.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'bitbake/lib/toaster/orm/models.py') diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index ba1eb0f2c8..1cf997cfe5 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -31,6 +31,7 @@ import django.db.models.signals import os.path import re +import itertools import logging logger = logging.getLogger("toaster") @@ -372,11 +373,37 @@ class Build(models.Model): build_name = models.CharField(max_length=100) bitbake_version = models.CharField(max_length=50) + @staticmethod + def get_recent(project=None): + """ + Return recent builds as a list; if project is set, only return + builds for that project + """ + + builds = Build.objects.all() + + if project: + builds = builds.filter(project=project) + + finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) + + recent_builds = list(itertools.chain( + builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), + builds.filter(finished_criteria).order_by("-completed_on")[:3] + )) + + # add percentage done property to each build; this is used + # to show build progress in mrb_section.html + for build in recent_builds: + build.percentDone = build.completeper() + + return recent_builds + def completeper(self): tf = Task.objects.filter(build = self) tfc = tf.count() if tfc > 0: - completeper = tf.exclude(order__isnull=True).count()*100/tf.count() + completeper = tf.exclude(order__isnull=True).count()*100/tfc else: completeper = 0 return completeper -- cgit v1.2.3-54-g00ecf