diff --git a/readthedocs/projects/views/private.py b/readthedocs/projects/views/private.py index 04d6d681b11..57e0d0761a3 100644 --- a/readthedocs/projects/views/private.py +++ b/readthedocs/projects/views/private.py @@ -7,6 +7,7 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User +from django.db.models import Count, OuterRef, Subquery from django.http import ( Http404, HttpResponseBadRequest, @@ -23,7 +24,7 @@ from vanilla import CreateView, DeleteView, DetailView, GenericView, UpdateView from readthedocs.builds.forms import VersionForm -from readthedocs.builds.models import Version +from readthedocs.builds.models import Build, Version from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin from readthedocs.core.utils import broadcast, prepare_build, trigger_build from readthedocs.integrations.models import HttpExchange, Integration @@ -92,7 +93,14 @@ def validate_primary_email(self, user): notification.send() def get_queryset(self): - return Project.objects.dashboard(self.request.user) + # Filters the builds for a perticular project. + builds = Build.objects.filter( + project=OuterRef('pk'), type='html', state='finished') + # Creates a Subquery object which returns + # the value of Build.success of the latest build. + sub_query = Subquery(builds.values('success')[:1]) + return Project.objects.dashboard(self.request.user).annotate( + build_count=Count('builds'), latest_build_success=sub_query) def get(self, request, *args, **kwargs): self.validate_primary_email(request.user) diff --git a/readthedocs/templates/projects/project_dashboard_base.html b/readthedocs/templates/projects/project_dashboard_base.html index 7394fd85dcb..7a18d58bb0b 100644 --- a/readthedocs/templates/projects/project_dashboard_base.html +++ b/readthedocs/templates/projects/project_dashboard_base.html @@ -66,7 +66,7 @@