Add count of open issues to detail page

This commit is contained in:
Lacey Williams Henschel
2022-12-12 12:34:49 -08:00
parent f7feb9b6a5
commit 681f92cfac
3 changed files with 32 additions and 1 deletions

View 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)

View File

@@ -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

View File

@@ -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">