mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-27 05:32:08 +00:00
📝 Redirect libraries list to libraries-by-version list
In case we want to preserve the /libraries/ url.
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import pytest
|
||||
|
||||
from model_bakery import baker
|
||||
|
||||
|
||||
def test_library_list(library, tp):
|
||||
def test_library_list(version, tp):
|
||||
"""GET /libraries/"""
|
||||
res = tp.get("libraries")
|
||||
tp.response_200(res)
|
||||
tp.response_302(res)
|
||||
assert res.url == f"/versions/{version.pk}/libraries/"
|
||||
|
||||
|
||||
@pytest.mark.xfail(
|
||||
reason="Need to change how the category filtering works to accommodate versions"
|
||||
)
|
||||
def test_library_list_select_category(library, category, tp):
|
||||
"""POST /libraries/ to submit a category redirects to the libraries-by-category page"""
|
||||
res = tp.post("libraries", data={"categories": category.pk})
|
||||
|
||||
@@ -19,25 +19,19 @@ class CategoryMixin:
|
||||
return context
|
||||
|
||||
|
||||
class LibraryList(CategoryMixin, FormMixin, ListView):
|
||||
"""List all of our libraries by name"""
|
||||
class LibraryList(RedirectView):
|
||||
"""
|
||||
Redirect a request for the list of libraries to the list of libraries
|
||||
for the most recent version of Boost
|
||||
"""
|
||||
|
||||
form_class = LibraryForm
|
||||
paginate_by = 25
|
||||
queryset = (
|
||||
Library.objects.prefetch_related("authors", "categories").all().order_by("name")
|
||||
)
|
||||
template_name = "libraries/list.html"
|
||||
permanent = False
|
||||
query_string = True
|
||||
pattern_name = "libraries-by-version"
|
||||
|
||||
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)
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
version = Version.objects.most_recent()
|
||||
return super().get_redirect_url(version_pk=version.pk)
|
||||
|
||||
|
||||
class LibraryByVersion(CategoryMixin, FormMixin, ListView):
|
||||
|
||||
Reference in New Issue
Block a user