From ecfcbaf3df6acacd25f662eefcfebe0b9347fe44 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 25 Dec 2022 00:21:49 +0200 Subject: [PATCH] make hat_active return a tuple --- files/classes/user.py | 56 ++++++++-------------------- files/routes/chat.py | 2 +- files/templates/chat.html | 2 +- files/templates/comments.html | 4 +- files/templates/header.html | 4 +- files/templates/log.html | 4 +- files/templates/notifications.html | 4 +- files/templates/user_in_table.html | 4 +- files/templates/user_listing.html | 4 +- files/templates/userpage/banner.html | 10 ++--- files/templates/util/macros.html | 4 +- 11 files changed, 37 insertions(+), 61 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index e7bb9f8ac..87117a766 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -253,52 +253,28 @@ class User(Base): if user_forced_hats: return random.choice(user_forced_hats) else: return None - @property @lazy - def hat_active(self): - if not FEATURES['HATS']: - return '' + def hat_active(self, v): + if FEATURES['HATS']: + if HOLIDAY_EVENT: + from files.events.helpers.const import EVENT_FORCED_HATS + if EVENT_FORCED_HATS: + return (random.choice(EVENT_FORCED_HATS), 'Merry Fistmas!') - if HOLIDAY_EVENT: - from files.events.helpers.const import EVENT_FORCED_HATS - if EVENT_FORCED_HATS: return random.choice(EVENT_FORCED_HATS) + if self.is_cakeday: + return ('/i/hats/Cakeday.webp', "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓") - if self.is_cakeday: - return '/i/hats/Cakeday.webp' + if self.age < NEW_USER_HAT_AGE: + return ('/i/new-user.webp', "Hi, I'm new here! Please be gentle :)") - if self.age < NEW_USER_HAT_AGE: - return '/i/new-user.webp' + if self.forced_hat: + return (f'/i/hats/{self.forced_hat[0]}.webp', self.forced_hat[1]) - if self.forced_hat: - return f'/i/hats/{self.forced_hat[0]}.webp' + if self.equipped_hat: + return (f'/i/hats/{self.equipped_hat.name}.webp', self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v)) - if self.equipped_hat: - return f'/i/hats/{self.equipped_hat.name}.webp' + return ('', '') - return '' - - @lazy - def hat_tooltip(self, v): - if not FEATURES['HATS']: - return '' - - if HOLIDAY_EVENT: - from files.events.helpers.const import EVENT_FORCED_HATS - if EVENT_FORCED_HATS: return 'Merry Christmas!' - - if self.is_cakeday: - return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓" - - if self.age < 86400 * 7: - return "Hi, I'm new here! Please be gentle :)" - - if self.forced_hat: - return self.forced_hat[1] - - if self.equipped_hat: - return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v) - - return '' @property @lazy @@ -760,7 +736,7 @@ class User(Base): 'url': self.url, 'id': self.id, 'profile_url': self.profile_url, - 'hat': self.hat_active, + 'hat': self.hat_active(v)[0], 'bannerurl': self.banner_url, 'bio_html': self.bio_html_eager, 'coins': self.coins, diff --git a/files/routes/chat.py b/files/routes/chat.py index fed870cd4..26ce0749a 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -71,7 +71,7 @@ def speak(data, v): "id": str(uuid.uuid4()), "quotes": quotes, "avatar": v.profile_url, - "hat": v.hat_active, + "hat": v.hat_active(v)[0], "user_id": v.id, "dm": bool(recipient and recipient != ""), "username": v.username, diff --git a/files/templates/chat.html b/files/templates/chat.html index fb169a267..deea7e9db 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -15,7 +15,7 @@ data-themecolor="{{v.themecolor}}" data-namecolor="{{v.namecolor}}" data-avatar="{{v.profile_url}}" - data-hat="{{v.hat_active}}"> + data-hat="{{v.hat_active(v)[0]}}"> {% if IS_LOCALHOST %} diff --git a/files/templates/comments.html b/files/templates/comments.html index f0ed37376..b5ffd352a 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -176,8 +176,8 @@
- {% if c.author.hat_active -%} - + {% if c.author.hat_active(v)[0] -%} + {%- endif %}
{{c.author_name}} diff --git a/files/templates/header.html b/files/templates/header.html index 3ccef382b..845010997 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -217,8 +217,8 @@
diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html index 521445491..f9fb8a8d2 100644 --- a/files/templates/userpage/banner.html +++ b/files/templates/userpage/banner.html @@ -9,11 +9,11 @@
-
+ @@ -270,8 +270,8 @@ diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 98aa90943..c3e7c4719 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -87,8 +87,8 @@
- {% if p.author.hat_active -%} - + {% if p.author.hat_active(v)[0] -%} + {%- endif %}
{{p.author_name}}