From 9ab49e0ecd924aafbfaaff76cfb00688ec01959a Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 11 Jun 2023 20:03:12 -0400 Subject: Fixed issue where tags exposed unpublished posts; also do not display tags with no posts --- blog/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blog/views.py b/blog/views.py index 2d2a9ebc..7863da98 100644 --- a/blog/views.py +++ b/blog/views.py @@ -54,10 +54,11 @@ def tags(request): tags = Tag.objects.all() # add occurance count to each tag for tag in tags: - tag.count = len(Post.objects.filter(tags__name__in=[tag.name])) + tag.count = len(Post.objects.filter(tags__name__in=[tag.name], is_public=True)) tag.pxs = 10 + tag.count * 2 if tag.count < 10 else 30 + tag.count tag.pxs = min(tag.pxs, 36) tags = sorted(tags, key=lambda x: x.count, reverse=True) + tags = [tag for tag in tags if tag.count > 0] return render(request, 'blog/tags.html', {'title': 'Tags', 'tags': tags}) def tag_posts(request, tag_slug): @@ -65,7 +66,7 @@ def tag_posts(request, tag_slug): tag = Tag.objects.get(slug=tag_slug) except Tag.DoesNotExist: raise Http404("Tag does not exist") - posts = Post.objects.filter(tags__name__in=[tag.name]).order_by('views') + posts = Post.objects.filter(tags__name__in=[tag.name], is_public=True).order_by('views') for post in posts: post.excerpt = add_excerpt(post) post.num_comments = add_num_comments(post) -- cgit v1.2.3