add the ability to order hats by author username

remotes/1693045480750635534/spooky-22
Aevann1 2022-09-05 10:27:37 +02:00
parent 7785f049ec
commit 93d7c91ce7
2 changed files with 17 additions and 8 deletions

View File

@ -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)

View File

@ -41,7 +41,11 @@
<th scope="col">Name</th>
<th scope="col">Description</th>
{% if SITE == 'rdrama.net' %}
<th scope="col">Author</th>
{% if request.values.get("sort") == 'author_asc' %}
<th scope="col"><a href="?sort=author_desc">Author</a></th>
{% else %}
<th scope="col"><a href="?sort=author_desc">Author</a></th>
{% endif %}
<th scope="col" onclick="sort_table(4)">Owners</th>
<th scope="col" onclick="sort_table(5)">Price</th>
{% else %}