From 678477b819c1a9d83e8634f1c892f72eb05f5d81 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 1 Apr 2024 21:58:29 +0200 Subject: [PATCH] dedup april fools code --- files/classes/comment.py | 2 +- files/classes/post.py | 2 +- files/classes/user.py | 11 +---------- files/templates/user_in_table.html | 2 +- files/templates/userpage/banner.html | 4 ++-- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 78f42e75f..664be55a1 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -341,7 +341,7 @@ class Comment(Base): @lazy def author_name(self): if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻' - return self.author.user_name + return self.author.switched.user_name @property @lazy diff --git a/files/classes/post.py b/files/classes/post.py index 4ad05e90b..1add08a2e 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -172,7 +172,7 @@ class Post(Base): @lazy def author_name(self): if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻' - return self.author.user_name + return self.author.switched.user_name @property @lazy diff --git a/files/classes/user.py b/files/classes/user.py index 712150ccb..1d01f5fc6 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1314,15 +1314,6 @@ class User(Base): @property @lazy def user_name(self): - if self.id != 2249 and not (has_request_context() and request.path == '/notifications/modmail'): - random.seed(self.id) - uid = random.choice(USER_IDS) - random.seed() - to_load = [User.username] - if SITE_NAME == 'rDrama': - to_load.append(User.earlylife) - self = g.db.query(User).options(load_only(*to_load)).filter_by(id=uid).one() - if self.earlylife: expiry = int(self.earlylife - time.time()) if expiry > 86400: @@ -1336,7 +1327,7 @@ class User(Base): @property @lazy def switched(self): - if self.id == 2249 or request.path == '/notifications/modmail': + if self.id == 2249 or (has_request_context() and request.path == '/notifications/modmail'): return self random.seed(self.id) diff --git a/files/templates/user_in_table.html b/files/templates/user_in_table.html index 0157507f0..2eec6b6be 100644 --- a/files/templates/user_in_table.html +++ b/files/templates/user_in_table.html @@ -8,7 +8,7 @@ {%- endif %} - {{user.username}} + {{user.user_name}} {% endif %} {% endif %} diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html index ccaa7c543..553a7e82b 100644 --- a/files/templates/userpage/banner.html +++ b/files/templates/userpage/banner.html @@ -28,7 +28,7 @@
{{userpage_admintools.userBanBlock('desktop')}}
-

{{u.username}}

+

{{u.user_name}}

{% if can_see(v, u) %} {% set ns.og_usernames = 'Reserved Usernames:' %} @@ -355,7 +355,7 @@
{{userpage_admintools.userBanBlock('mobile')}} -
{{u.username}}
+
{{u.user_name}}
{% if can_see(v, u) and ns.og_usernames != 'Reserved Usernames:' %}