forked from MarseyWorld/MarseyWorld
add the ability to order hats by author username
parent
7785f049ec
commit
93d7c91ce7
|
@ -13,15 +13,20 @@ def hats(v):
|
||||||
|
|
||||||
owned_hat_ids = [x.hat_id for x in v.owned_hats]
|
owned_hat_ids = [x.hat_id for x in v.owned_hats]
|
||||||
|
|
||||||
if v.equipped_hat_ids:
|
if request.values.get("sort") == 'author_asc':
|
||||||
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()
|
hats = g.db.query(HatDef, User).join(HatDef.author).order_by(User.username).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()
|
elif request.values.get("sort") == 'author_desc':
|
||||||
owned = equipped + not_equipped
|
hats = g.db.query(HatDef, User).join(HatDef.author).order_by(User.username.desc()).all()
|
||||||
else:
|
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()
|
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
|
hats = owned + not_owned
|
||||||
|
|
||||||
sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar()
|
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)
|
return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v, sales=sales)
|
||||||
|
|
|
@ -41,7 +41,11 @@
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col">Description</th>
|
<th scope="col">Description</th>
|
||||||
{% if SITE == 'rdrama.net' %}
|
{% 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(4)">Owners</th>
|
||||||
<th scope="col" onclick="sort_table(5)">Price</th>
|
<th scope="col" onclick="sort_table(5)">Price</th>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Reference in New Issue