add stats to user page

This commit is contained in:
Lera Elvoé 2025-07-01 20:29:15 +03:00
parent 2345830074
commit df239fb130
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
2 changed files with 50 additions and 8 deletions

View File

@ -4,6 +4,9 @@ from .constants import PermissionLevel
class Users(Model): class Users(Model):
table = "users" table = "users"
def get_avatar_url(self):
return Avatars.find({"id": self.avatar_id}).file_path
def is_guest(self): def is_guest(self):
return self.permission == PermissionLevel.GUEST.value return self.permission == PermissionLevel.GUEST.value

View File

@ -24,13 +24,52 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
<div> <div class="user-info">
<div class="user-page-usercard">
<div class="usercard-inner">
<img class="avatar" src="{{ target_user.get_avatar_url() }}">
<strong class="big">{{ target_user.username }}</strong>
{% if target_user.status %}
<em class="user-status">{{ target_user.status }}</em>
{% endif %}
{% if target_user.signature_rendered %}
Signature:
<div>{{ target_user.signature_rendered | safe }}</div>
{% endif %}
</div>
</div>
<div class="user-page-stats">
{% with stats = target_user.get_post_stats() %} {% with stats = target_user.get_post_stats() %}
<ul> <ul class="user-stats-list">
<li>Permission: {{ target_user.permission }}</li>
<li>Posts created: {{ stats.post_count }}</li> <li>Posts created: {{ stats.post_count }}</li>
<li>Threads started: {{ stats.thread_count }}</li> <li>Threads started: {{ stats.thread_count }}</li>
<li>Latest started thread: {{ stats.latest_thread_title }} {% if stats.latest_thread_title %}
<li>Latest started thread: <a href="{{ url_for("threads.thread", slug = stats.latest_thread_slug) }}">{{ stats.latest_thread_title }}</a>
{% endif %}
</ul> </ul>
{% endwith %} {% endwith %}
Latest posts:
{% with posts = target_user.get_latest_posts() %}
<div class="user-page-posts">
{% for post in posts %}
<div class="post-content-container">
<div class="post-info">
<a href="{{ url_for("threads.thread", slug=post.thread_slug, after=post.id) }}" title="permalink"><i>
{% if (post.edited_at | int) > (post.created_at | int) %}
Edited on {{ timestamp(post.edited_at) }}
{% else %}
Posted on {{ timestamp(post.edited_at) }}
{% endif %}
</i></a>
</div>
<div class="post-content wider user-page-post-preview">
<div class="post-inner">{{ post.content | safe }}</div>
</div>
</div>
{% endfor %}
</div>
{% endwith %}
</div>
</div> </div>
{% endblock %} {% endblock %}