diff --git a/files/classes/user.py b/files/classes/user.py index c01218a03..b738d2db1 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -153,6 +153,8 @@ class User(Base): awards = relationship("AwardRelationship", primaryjoin="User.id==AwardRelationship.user_id", back_populates="user") referrals = relationship("User") equipped_hat = relationship("HatDef", primaryjoin="User.equipped_hat_id==HatDef.id") + designed_hats = relationship("HatDef", primaryjoin="User.id==HatDef.author_id") + owned_hats = relationship("Hat") def __init__(self, **kwargs): @@ -174,13 +176,13 @@ class User(Base): @property @lazy - def num_of_hats_bought(self): - return g.db.query(Hat).filter_by(user_id=self.id).count() + def num_of_owned_hats(self): + return len(self.owned_hats) @property @lazy - def num_of_hats_designed(self): - return g.db.query(HatDef).filter_by(author_id=self.id).count() + def num_of_designed_hats(self): + return len(self.designed_hats) @property @lazy diff --git a/files/routes/hats.py b/files/routes/hats.py index df25caea5..13598ffc6 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -55,11 +55,11 @@ def buy_hat(v, hat_id): f":marseycapitalistmanlet: @{v.username} has just bought `{hat.name}`, you have received your 5% cut ({int(hat.price * 0.05)} {currency}) :!marseycapitalistmanlet:" ) - if v.num_of_hats_bought >= 250: + if v.num_of_owned_hats >= 250: badge_grant(user=v, badge_id=154) - elif v.num_of_hats_bought >= 100: + elif v.num_of_owned_hats >= 100: badge_grant(user=v, badge_id=153) - elif v.num_of_hats_bought >= 25: + elif v.num_of_owned_hats >= 25: badge_grant(user=v, badge_id=152) return {"message": "Hat bought!"} diff --git a/files/routes/users.py b/files/routes/users.py index 7618d8960..dcab2310a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -576,12 +576,16 @@ def leaderboard(v): FROM (SELECT target_id, count(target_id) AS n FROM userblocks GROUP BY target_id) AS blk \ JOIN users ON users.id = blk.target_id ORDER BY blk.n DESC LIMIT 25')) + users16 = g.db.query(User, func.count(User.owned_hats)).join(User.owned_hats).group_by(User).order_by(func.count(User.owned_hats).desc()).limit(25).all() + + users17 = g.db.query(User, func.count(User.designed_hats)).join(User.designed_hats).group_by(User).order_by(func.count(User.designed_hats).desc()).limit(25).all() + return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2, users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5, users6=users6, pos6=pos6, users7=users7, pos7=pos7, users9=users9_25, pos9=pos9, users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users13=users13_25, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15, - usersBlk=usersBlk) + usersBlk=usersBlk, users16=users16, users17=users17) @app.get("//css") def get_css(id): diff --git a/files/templates/hats.html b/files/templates/hats.html index 2c13660df..ec8ef238c 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -9,8 +9,8 @@ {% block Banner %}
hats banner -
Number of hats you bought: {{v.num_of_hats_bought}}
-
Number of hats you designed: {{v.num_of_hats_designed}}
+
Number of hats you bought: {{v.num_of_owned_hats}}
+
Number of hats you designed: {{v.num_of_designed_hats}}
Coins you spent on hats: {{v.coins_spent_on_hats}}
{% endblock %} diff --git a/files/templates/leaderboard.html b/files/templates/leaderboard.html index 9d5da9033..ddd944645 100644 --- a/files/templates/leaderboard.html +++ b/files/templates/leaderboard.html @@ -19,7 +19,9 @@ {%- if users13 %}Upvotes Given • {% endif -%} WinningsLosses • - Blocked + Blocked • + Owned Hats • + Designed Hats
Top 25 by coins
@@ -427,6 +429,46 @@ {% endfor %} + +
Top 25 by Owned Hats
+ +
+ + + + + + + +{% for user,num in users16 %} + + + + + +{% endfor %} +
#NameOwned Hats
{{loop.index}}{{user.username}}{{num}}
+ +
Top 25 by Designed Hats
+ +
+ + + + + + + +{% for user,num in users17 %} + + + + + +{% endfor %} +
#NameDesigned Hats
{{loop.index}}{{user.username}}{{num}}
+ +