Add libraries-by-version list view

Note: This does NOT address the categories functionality. This commit adds the new URL, but if the user filters by category on that page, the page redirects to `/libraries-by-category/` and doesn't respect the version.
This commit is contained in:
Lacey Williams Henschel
2023-02-02 09:35:13 -08:00
parent 345de0c4c0
commit 7e7db0b218
3 changed files with 47 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ from libraries.views import (
LibraryList,
LibraryByCategory,
LibraryDetail,
LibraryListByVersion,
)
from libraries.api import LibrarySearchView
from support.views import SupportView, ContactView
@@ -132,7 +133,13 @@ urlpatterns = [
TemplateView.as_view(template_name="support/getting_started.html"),
name="getting-started",
),
path("contact/", ContactView.as_view(), name="contact"),
path("contact/", ContactView.as_view(), name="contact"),\
# Boost versions views
path(
"versions/<slug:slug>/libraries/",
LibraryListByVersion.as_view(),
name="libraries-by-version",
),
path("versions/<slug:slug>/", VersionDetail.as_view(), name="version-detail"),
path("versions/", VersionList.as_view(), name="version-list"),
# Markdown content

View File

@@ -26,6 +26,20 @@ def test_libraries_by_category(tp, library, category):
assert res.context["category"] == category
def test_libraries_by_version(tp, library_version):
"""GET /versions/{version_identifier}/libraries/"""
# Create a new library_version
excluded_library = baker.make("libraries.Library", name="Sample")
res = tp.get("libraries-by-version", library_version.version.slug)
tp.response_200(res)
assert "library_list" in res.context
# Confirm that correct libraries are present
assert len(res.context["library_list"]) == 1
assert library_version.library in res.context["library_list"]
assert excluded_library not in res.context["library_list"]
def test_library_detail(library, tp):
"""GET /libraries/{repo}/"""
url = tp.reverse("library-detail", library.slug)

View File

@@ -38,6 +38,31 @@ class LibraryList(CategoryMixin, FormMixin, ListView):
return super().get(request)
class LibraryListByVersion(CategoryMixin, FormMixin, ListView):
"""List all of our libraries for a specific Boost version by name"""
form_class = LibraryForm
paginate_by = 25
queryset = (
Library.objects.prefetch_related("authors", "categories").all().order_by("name")
)
template_name = "libraries/list.html"
def get_queryset(self):
version_slug = self.kwargs.get("slug")
return super().get_queryset().filter(library_version__version__slug=version_slug)
def post(self, request):
"""User has submitted a form and will be redirected to the right results"""
form = self.get_form()
if form.is_valid():
category = form.cleaned_data["categories"][0]
return redirect("libraries-by-category", category=category.slug)
else:
logger.info("library_list_invalid_category")
return super().get(request)
class LibraryByCategory(CategoryMixin, ListView):
"""List all of our libraries in a certain category"""