aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-06-11 20:03:12 -0400
committerBobby <[email protected]>2023-06-11 20:03:12 -0400
commit9ab49e0ecd924aafbfaaff76cfb00688ec01959a (patch)
treed3173cec46261c385b13f5a76539ae8fc73c24c8
parent2be0508590faba7ebb5914ba972f5f3a23332e45 (diff)
downloadthatcomputerscientist-9ab49e0ecd924aafbfaaff76cfb00688ec01959a.tar.xz
thatcomputerscientist-9ab49e0ecd924aafbfaaff76cfb00688ec01959a.zip
Fixed issue where tags exposed unpublished posts; also do not display tags with no posts
-rw-r--r--blog/views.py5
1 files 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)