mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-26 05:12:11 +00:00
✨ Add count of open issues to detail page
This commit is contained in:
15
libraries/tests/test_views.py
Normal file
15
libraries/tests/test_views.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def test_library_list(library, tp):
|
||||
res = tp.get("libraries")
|
||||
tp.response_200(res)
|
||||
|
||||
|
||||
def test_library_detail(library, tp):
|
||||
url = tp.reverse("library-detail", library.slug)
|
||||
|
||||
with patch("libraries.views.LibraryDetail.get_open_issues_count") as count_mock:
|
||||
count_mock.return_value = 21
|
||||
res = tp.get(url)
|
||||
tp.response_200(res)
|
||||
@@ -1,5 +1,6 @@
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
||||
from .github import repo_issues
|
||||
from .models import Category, Library
|
||||
|
||||
|
||||
@@ -55,3 +56,18 @@ class LibraryDetail(CategoryMixin, DetailView):
|
||||
|
||||
model = Library
|
||||
template_name = "libraries/detail.html"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
context = self.get_context_data(object=self.object)
|
||||
context["open_issues_count"] = self.get_open_issues_count(self.object)
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_open_issues_count(self, obj):
|
||||
try:
|
||||
issues = repo_issues(
|
||||
obj.github_owner, obj.github_repo, state="open", issues_only=True
|
||||
)
|
||||
return len(issues)
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
<div class="py-6">
|
||||
<h3 class="text-2xl mb-1">Open Issues</h3>
|
||||
Y
|
||||
{{ open_issues_count }}
|
||||
</div>
|
||||
|
||||
<div class="py-6">
|
||||
|
||||
Reference in New Issue
Block a user