mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
- 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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
17
ak/views.py
17
ak/views.py
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user