diff --git a/files/classes/user.py b/files/classes/user.py index 93f1724f1..c43572d1f 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -171,11 +171,6 @@ class User(Base): def __repr__(self): return f"" - @property - @lazy - def owned_hats(self): - return [x[0] for x in g.db.query(Hat.hat_id).filter_by(user_id=self.id).all()] - @property @lazy def name_color(self): diff --git a/files/routes/hats.py b/files/routes/hats.py index b9a5b746a..151bfd84c 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -10,9 +10,11 @@ from flask import g def hats(v): if not FEATURES['HATS']: abort(404) - hats = g.db.query(HatDef, User).join(HatDef.author).order_by(HatDef.price).all() + owned_hats = [x[0] for x in g.db.query(Hat.hat_id).filter_by(user_id=v.id).all()] + owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hats)).order_by(HatDef.price).all() + not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.notin_(owned_hats)).order_by(HatDef.price).all() - return render_template("hats.html", hats=hats, v=v) + return render_template("hats.html", owned=owned, not_owned=not_owned, v=v) @app.post("/buy_hat/") @auth_required diff --git a/files/templates/hats.html b/files/templates/hats.html index 5cd92f6c6..8a8f1c8cb 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -27,7 +27,7 @@ - {% for hat, user in hats %} + {% for hat, user in owned %} {{hat.name}} {{hat.name}} @@ -37,22 +37,33 @@ {% endif %} {{hat.price}} - {% if hat.id in v.owned_hats %} - {% if hat.id == v.equipped_hat.id %} - Unequip - {% else %} - Equip - {% endif %} + {% if hat.id == v.equipped_hat.id %} + Unequip {% else %} - Buy + Equip + {% endif %} + + + {% endfor %} - Are you sure? + {% for hat, user in not_owned %} + + {{hat.name}} + {{hat.name}} + {{hat.description}} + {% if SITE == 'rdrama.net' %} + {{user.username}} + {% endif %} + {{hat.price}} + + Buy - {% if FEATURES['PROCOINS'] %} - Buy with MBux + Are you sure? - Are you sure? - {% endif %} + {% if FEATURES['PROCOINS'] %} + Buy with MBux + + Are you sure? {% endif %}