From a981700701c41c7bbb6a9778e95f691278c5c294 Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Fri, 13 Nov 2015 13:48:34 +0000 Subject: [PATCH] toaster: orm Fix get_number_of_builds to count all apart from IN_PROGRESS The count of a project's builds should not include those which are currently in progress. Signed-off-by: Michael Wood Signed-off-by: Elliot Smith Signed-off-by: Richard Purdie --- lib/toaster/orm/models.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py index 3832905838f..0ac94b9339d 100644 --- a/lib/toaster/orm/models.py +++ b/lib/toaster/orm/models.py @@ -130,13 +130,12 @@ class Project(models.Model): try: return self.projectvariable_set.get(name="MACHINE").value except (ProjectVariable.DoesNotExist,IndexError): - return( "None" ); + return None; def get_number_of_builds(self): - try: - return len(Build.objects.filter( project = self.id )) - except (Build.DoesNotExist,IndexError): - return( 0 ) + """Return the number of builds which have ended""" + + return self.build_set.filter(~Q(outcome=Build.IN_PROGRESS)).count() def get_last_build_id(self): try: -- 2.47.2