- Add featured field to Library model

- Add featured library to context of home page
- Add the featured library to the homepage template
- Return a random library if no library is marked as featured
- Add link to library detail page
- Add default author image
- Add hover text with author name
- Limit "random" featured library to libraries within the most recent Boost version
This commit is contained in:
Lacey Williams Henschel
2023-08-17 15:22:50 -07:00
parent be01471015
commit d3d9572ad6
5 changed files with 73 additions and 21 deletions

View File

@@ -4,7 +4,7 @@ import pytest
from django.test.utils import override_settings
def test_homepage(version, tp):
def test_homepage(library, version, tp):
"""Ensure we can hit the homepage"""
# Use any page that is named 'home' otherwise use /
url = tp.reverse("home")
@@ -15,12 +15,12 @@ def test_homepage(version, tp):
assert "entries" in response.context
assert "latest_version" in response.context
assert response.context["latest_version"] == version
assert "featured_library" in response.context
def test_homepage_beta(db, tp):
"""Ensure we can hit the beta homepage"""
url = tp.reverse("home-beta")
tp.get_check_200(url)

View File

@@ -22,9 +22,24 @@ class HomepageView(TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["entries"] = Entry.objects.published().order_by("-publish_at")[:3]
context["latest_version"] = Version.objects.most_recent()
latest_version = Version.objects.most_recent()
context["latest_version"] = latest_version
context["featured_library"] = self.get_featured_library(latest_version)
return context
def get_featured_library(self, latest_version):
library = Library.objects.filter(featured=True).first()
# If we don't have a featured library, return a random library
if not library:
library = (
Library.objects.filter(library_version__version=latest_version)
.order_by("?")
.first()
)
return library
class HomepageBetaView(TemplateView):
"""