mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-27 05:32:08 +00:00
✨ Add count of closed PRs to library detail page
This commit is contained in:
@@ -14,10 +14,28 @@ def test_library_detail(library, tp):
|
||||
tp.response_200(response)
|
||||
|
||||
|
||||
def test_library_detail_issues_context(tp, library):
|
||||
def test_library_detail_context_get_closed_prs_count(tp, library):
|
||||
"""
|
||||
GET /libraries/{repo}/
|
||||
Test that the custom context vars appear as expected
|
||||
Test that the custom closed_prs_count var appears as expected
|
||||
"""
|
||||
# Create open and closed PRs for this library, and another random PR
|
||||
lib2 = baker.make("libraries.Library", slug="sample")
|
||||
baker.make("libraries.PullRequest", library=library, is_open=True)
|
||||
baker.make("libraries.PullRequest", library=library, is_open=False)
|
||||
baker.make("libraries.PullRequest", library=lib2, is_open=True)
|
||||
url = tp.reverse("library-detail", library.slug)
|
||||
response = tp.get(url)
|
||||
tp.response_200(response)
|
||||
assert "closed_prs_count" in response.context
|
||||
# Verify that the count only includes the one open PR for this library
|
||||
assert response.context["closed_prs_count"] == 1
|
||||
|
||||
|
||||
def test_library_detail_context_get_open_issues_count(tp, library):
|
||||
"""
|
||||
GET /libraries/{repo}/
|
||||
Test that the custom open_issues_count var appears as expected
|
||||
"""
|
||||
# Create open and closed issues for this library, and another random issue
|
||||
lib2 = baker.make("libraries.Library", slug="sample")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
||||
from .models import Category, Issue, Library
|
||||
from .models import Category, Issue, Library, PullRequest
|
||||
|
||||
|
||||
class CategoryMixin:
|
||||
@@ -59,8 +59,12 @@ class LibraryDetail(CategoryMixin, DetailView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
context = self.get_context_data(object=self.object)
|
||||
context["closed_prs_count"] = self.get_closed_prs_count(self.object)
|
||||
context["open_issues_count"] = self.get_open_issues_count(self.object)
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_closed_prs_count(self, obj):
|
||||
return PullRequest.objects.filter(library=obj, is_open=True).count()
|
||||
|
||||
def get_open_issues_count(self, obj):
|
||||
return Issue.objects.filter(library=obj, is_open=True).count()
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<div class="md:flex my-4 md:my-11 py-6 md:justify-between">
|
||||
<div class="py-6">
|
||||
<h3 class="text-2xl mb-1">Closed Pull Requests</h3>
|
||||
X per Month
|
||||
{{ closed_prs_count }}
|
||||
</div>
|
||||
|
||||
<div class="py-6">
|
||||
|
||||
Reference in New Issue
Block a user