Only show published tags

This commit is contained in:
Jake Howard 2024-01-27 19:53:28 +00:00
parent 552639ec40
commit ae4ea780b7
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 7 additions and 7 deletions

View file

@ -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`.

View file

@ -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:

View file

@ -20,14 +20,14 @@
</div>
{% endif %}
{% if page.tags.all %}
{% if page.tags.public.live.all %}
<div class="icon-text is-family-code">
<span class="icon">
<a href="{{ page.tag_list_page_url }}" title="View all tags">
<i class="fas fa-lg fa-tags"></i>
</a>
</span>
{% for tag in page.tags.all|dictsort:"slug" %}
{% for tag in page.tags.public.live.all|dictsort:"slug" %}
<span><a title="{{ tag.name }}" href="{% pageurl tag %}">#{{ tag.slug }}</a></span>
{% endfor %}
</div>

View file

@ -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]:

View file

@ -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)