Add post count, image count, and unique posters to post detail

Just like 4chan has!!!!!!!

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-07-12 21:12:16 -07:00
parent 5df21ccb95
commit 3f1615f058
3 changed files with 25 additions and 0 deletions

View File

@@ -135,6 +135,18 @@ class Post(models.Model):
self.__make_thumbnail() self.__make_thumbnail()
super(Post, self).save(*args, **kwargs) 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): def __make_thumbnail(self):
image = Image.open(self.image) image = Image.open(self.image)
image.thumbnail(settings.THUMB_SIZE, Image.ANTIALIAS) image.thumbnail(settings.THUMB_SIZE, Image.ANTIALIAS)

View File

@@ -108,6 +108,10 @@ th {
font-weight: bold; font-weight: bold;
} }
.post_stats {
float: right;
}
.post { .post {
background-color: var(--post-background); background-color: var(--post-background);
padding: 10px; padding: 10px;

View File

@@ -29,6 +29,15 @@
</div> </div>
{# return links #} {# return links #}
[ <a href="{% url 'board:board_detail' board.url %}">{% translate "Return" %}</a> ] [ <a href="{% url 'board:board_detail' board.url %}">{% translate "Return" %}</a> ]
{# posts / images / poster count / page #}
<span class="post_stats">[
<span title="{% translate 'Post replies' %}">{{post.replies.count}}</span>
/
<span title="{% translate 'Image replies' %}">{{post.image_replies_count}}</span>
/
<span title="{% translate 'Unique posters in this thread' %}">{{post.unique_posters}}</span>
]
</span>
<hr /> <hr />
{# posts #} {# posts #}
<div class="row post"> <div class="row post">