From ae4ea780b776aeb21d2571a96226c9d32255bddd Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Jan 2024 19:53:28 +0000 Subject: [PATCH] Only show published tags --- website/blog/models.py | 2 +- website/blog/tests.py | 4 ++-- website/common/templates/common/content-details.html | 4 ++-- website/common/views.py | 2 +- website/legacy/views.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/website/blog/models.py b/website/blog/models.py index dd8289b..5615841 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -79,7 +79,7 @@ class BlogPostPage(BaseContentPage): else models.Value(1), ) - page_tags = list(self.tags.values_list("id", flat=True)) + page_tags = list(self.tags.public().live().values_list("id", flat=True)) similar_posts = similar_posts.alias( # If this page has no tags, ignore it as part of similarity # NB: Cast to a float, because `COUNT` returns a `bigint`. diff --git a/website/blog/tests.py b/website/blog/tests.py index f9006b3..e4883bf 100644 --- a/website/blog/tests.py +++ b/website/blog/tests.py @@ -18,7 +18,7 @@ class BlogPostPageTestCase(TestCase): self.assertEqual(response.status_code, 200) def test_queries(self) -> None: - with self.assertNumQueries(41): + with self.assertNumQueries(43): self.client.get(self.page.url) @@ -76,7 +76,7 @@ class BlogPostListPageTestCase(TestCase): self.assertEqual(len(response.context["listing_pages"]), 2) def test_queries(self) -> None: - with self.assertNumQueries(37): + with self.assertNumQueries(39): self.client.get(self.page.url) def test_feed_accessible(self) -> None: diff --git a/website/common/templates/common/content-details.html b/website/common/templates/common/content-details.html index e99f06b..4f84a6f 100644 --- a/website/common/templates/common/content-details.html +++ b/website/common/templates/common/content-details.html @@ -20,14 +20,14 @@ {% endif %} - {% if page.tags.all %} + {% if page.tags.public.live.all %}
- {% for tag in page.tags.all|dictsort:"slug" %} + {% for tag in page.tags.public.live.all|dictsort:"slug" %} #{{ tag.slug }} {% endfor %}
diff --git a/website/common/views.py b/website/common/views.py index fc0aa13..36ffa91 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -127,7 +127,7 @@ class AllPagesFeed(Feed): def item_categories(self, item: BasePage) -> Optional[list[str]]: if tags := getattr(item, "tags", None): - return tags.order_by("slug").values_list("slug", flat=True) + return tags.public().live().order_by("slug").values_list("slug", flat=True) return None def item_enclosure_url(self, item: BasePage) -> Optional[str]: diff --git a/website/legacy/views.py b/website/legacy/views.py index 333c7ab..5b2aac1 100644 --- a/website/legacy/views.py +++ b/website/legacy/views.py @@ -17,7 +17,7 @@ class TagView(RedirectView): permanent = True def get_redirect_url(self, slug: str) -> str: - tag = get_object_or_404(BlogPostTagPage, slug=slug) + tag = get_object_or_404(BlogPostTagPage.objects.public().live(), slug=slug) return tag.get_url(request=self.request)