From 93d7c91ce7d328d2db468fa74efbda276dc22739 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 5 Sep 2022 10:27:37 +0200 Subject: [PATCH] add the ability to order hats by author username --- files/routes/hats.py | 19 ++++++++++++------- files/templates/hats.html | 6 +++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/files/routes/hats.py b/files/routes/hats.py index 2ad379376..1f0e60d6a 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -13,15 +13,20 @@ def hats(v): owned_hat_ids = [x.hat_id for x in v.owned_hats] - if v.equipped_hat_ids: - equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids), HatDef.id.in_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all() - not_equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids), HatDef.id.notin_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all() - owned = equipped + not_equipped + if request.values.get("sort") == 'author_asc': + hats = g.db.query(HatDef, User).join(HatDef.author).order_by(User.username).all() + elif request.values.get("sort") == 'author_desc': + hats = g.db.query(HatDef, User).join(HatDef.author).order_by(User.username.desc()).all() else: - owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all() + if v.equipped_hat_ids: + equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids), HatDef.id.in_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all() + not_equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids), HatDef.id.notin_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all() + owned = equipped + not_equipped + else: + owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all() - not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.notin_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all() - hats = owned + not_owned + not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.notin_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all() + hats = owned + not_owned sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar() return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v, sales=sales) diff --git a/files/templates/hats.html b/files/templates/hats.html index e56222004..621e0bc75 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -41,7 +41,11 @@ Name Description {% if SITE == 'rdrama.net' %} - Author + {% if request.values.get("sort") == 'author_asc' %} + Author + {% else %} + Author + {% endif %} Owners Price {% else %}