From 3f1615f058dc58af3bc3b338f540c3828525b232 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 12 Jul 2022 21:12:16 -0700 Subject: [PATCH] Add post count, image count, and unique posters to post detail Just like 4chan has!!!!!!! Signed-off-by: Alek Ratzloff --- board/models.py | 12 ++++++++++++ board/static/board/style.css | 4 ++++ board/templates/board/post_detail.html | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/board/models.py b/board/models.py index 70efc76..f5bab15 100644 --- a/board/models.py +++ b/board/models.py @@ -135,6 +135,18 @@ class Post(models.Model): self.__make_thumbnail() super(Post, self).save(*args, **kwargs) + def image_replies_count(self) -> int: + """ + Gets the number of image replies to this OP. + """ + # I would normally use the filter() and count() functions here, but + # image__isnull=True does not seem to behave correctly. This is close + # enough. + return len([p for p in self.replies.all() if p.image]) + + def unique_posters(self) -> int: + return len(set(p.ip for p in self.replies.all())) + def __make_thumbnail(self): image = Image.open(self.image) image.thumbnail(settings.THUMB_SIZE, Image.ANTIALIAS) diff --git a/board/static/board/style.css b/board/static/board/style.css index b448608..d3f2c05 100644 --- a/board/static/board/style.css +++ b/board/static/board/style.css @@ -108,6 +108,10 @@ th { font-weight: bold; } +.post_stats { + float: right; +} + .post { background-color: var(--post-background); padding: 10px; diff --git a/board/templates/board/post_detail.html b/board/templates/board/post_detail.html index 95d2d4b..5c7fc1a 100644 --- a/board/templates/board/post_detail.html +++ b/board/templates/board/post_detail.html @@ -29,6 +29,15 @@ {# return links #} [ {% translate "Return" %} ] +{# posts / images / poster count / page #} +[ + {{post.replies.count}} + / + {{post.image_replies_count}} + / + {{post.unique_posters}} + ] +
{# posts #}