Move user hat properties for userpage to model.

remotes/1693176582716663532/tmp_refs/heads/watchparty
Snakes 2022-10-08 16:30:27 -04:00
parent 8bb145d23c
commit 10921331fa
Signed by: Snakes
GPG Key ID: E745A82778055C7E
3 changed files with 13 additions and 9 deletions

View File

@ -208,6 +208,13 @@ class User(Base):
def num_of_owned_hats(self):
return len(self.owned_hats)
@property
@lazy
def hats_owned_proportion_display(self):
total_num_of_hats = g.db.query(HatDef).filter(HatDef.submitter_id == None).count()
proportion = f'{float(self.num_of_owned_hats) / total_num_of_hats:.1%}'
return (proportion, total_num_of_hats)
@property
@lazy
def num_of_designed_hats(self):

View File

@ -994,9 +994,6 @@ def u_username(username, v=None):
listing = get_posts(ids, v=v)
# this is probably totalllly inefficient but maybe someone can fix it later
total_num_of_hats = g.db.query(HatDef).filter(HatDef.submitter_id == None).count()
if u.unban_utc:
if request.headers.get("Authorization") or request.path.endswith(".json"):
return {"data": [x.json for x in listing]}
@ -1010,8 +1007,7 @@ def u_username(username, v=None):
sort=sort,
t=t,
next_exists=next_exists,
is_following=is_following,
total_num_of_hats=total_num_of_hats)
is_following=is_following)
if request.headers.get("Authorization") or request.path.endswith(".json"):
return {"data": [x.json for x in listing]}
@ -1024,8 +1020,7 @@ def u_username(username, v=None):
sort=sort,
t=t,
next_exists=next_exists,
is_following=is_following,
total_num_of_hats=total_num_of_hats)
is_following=is_following)
@app.get("/@<username>/comments")

View File

@ -30,6 +30,8 @@
{% endblock %}
{% import 'userpage_admintools.html' as userpage_admintools with context %}
{% set hats_total = u.hats_owned_proportion_display[1] %}
{% set hats_owned_percent = u.hats_owned_proportion_display[0] %}
{% block desktopUserBanner %}
@ -253,7 +255,7 @@
<p id="profile--info--spent">Coins spent: {{u.coins_spent}}</p>
<p id="profile--info--truescore">True score: {{u.truecoins}}</p>
<p id="profile--info--winnings">Winnings: {{u.winnings}}</p>
<p id="profile--info--hats-owned" {% if u.num_of_owned_hats == total_num_of_hats %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{total_num_of_hats}} hats owned ({{ '{:.0%}'.format(u.num_of_owned_hats / total_num_of_hats) }})</p>
<p id="profile--info--hats-owned" {% if u.num_of_owned_hats == hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})</p>
{% if u.is_private %}
<p id="profile--info--private">User has private mode enabled</p>
{% endif %}
@ -497,7 +499,7 @@
<p id="profile-mobile--info--spent">Coins spent: {{u.coins_spent}}</p>
<p id="profile-mobile--info--truescore">True score: {{u.truecoins}}</p>
<p id="profile-mobile--info--winnings">Winnings: {{u.winnings}}</p>
<p id="profile-mobile--info--hats-owned" {% if u.num_of_owned_hats == total_num_of_hats %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{total_num_of_hats}} hats owned ({{ '{:.0%}'.format(u.num_of_owned_hats / total_num_of_hats) }})</p>
<p id="profile-mobile--info--hats-owned" {% if u.num_of_owned_hats == hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})</p>
{% if u.is_private %}
<p id="profile-mobile--info--private">User has private mode enabled</p>
{% endif %}