From 091679142e4034bbe450eb3db94c223e1d3021f3 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Wed, 28 Jul 2021 17:37:38 +0200 Subject: [PATCH] sneed --- drama/classes/user.py | 22 ++++++++++++++++++++++ drama/routes/users.py | 4 ++-- drama/templates/userpage.html | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drama/classes/user.py b/drama/classes/user.py index 3d668d68c9..2df1f5e78e 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -277,6 +277,28 @@ class User(Base, Stndrd, Age_times): def __repr__(self): return f"" + @property + def unban_string(self): + if self.unban_utc == 0: + return "permanently banned" + + wait = self.unban_utc - int(time.time()) + + if wait < 60: + text = "a few moments" + else: + days = wait//(24*60*60) + wait -= days*24*60*60 + + hours = wait//(60*60) + wait -= hours*60*60 + + mins = wait//60 + + text = f"{days} days {hours:02d} hours {mins:02d} minutes" + + return f"Unban in {text}" + @property @lazy def post_notifications_count(self): diff --git a/drama/routes/users.py b/drama/routes/users.py index eaade85f33..839021d19c 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -304,9 +304,9 @@ def u_username(username, v=None): listing = get_posts(ids, v=v) if u.unban_utc: - unban = datetime.fromtimestamp(u.unban_utc).strftime('%c') + #unban = datetime.fromtimestamp(u.unban_utc).strftime('%c') return {'html': lambda: render_template("userpage.html", - unban=unban, + unban=u.unban_string, u=u, v=v, listing=listing, diff --git a/drama/templates/userpage.html b/drama/templates/userpage.html index 4eea1f9ad5..caf74f901f 100644 --- a/drama/templates/userpage.html +++ b/drama/templates/userpage.html @@ -67,7 +67,7 @@
{% if u.is_banned %}
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
- {% if unban %}
until {{unban}}
{% endif %} + {% if unban %}
{{unban}}
{% endif %} {% endif %}
@@ -282,7 +282,7 @@
{% if u.is_banned %}
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
- {% if unban %}
until {{unban}}
{% endif %} + {% if unban %}
{{unban}}
{% endif %} {% endif %}

{{u.username}}