forked from rDrama/rDrama
make /hats more intuitive
parent
5feb479cd2
commit
5d704a2cb2
|
@ -11,11 +11,17 @@ from flask import g
|
|||
def hats(v):
|
||||
if not FEATURES['HATS']: abort(404)
|
||||
|
||||
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, HatDef.name).all()
|
||||
not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.notin_(owned_hats)).order_by(HatDef.price, HatDef.name).all()
|
||||
owned_hat_ids = [x.hat_id for x in v.owned_hats]
|
||||
|
||||
return render_template("hats.html", owned=owned, not_owned=not_owned, v=v)
|
||||
if v.equipped_hat_id:
|
||||
owned = [(v.equipped_hat, v.equipped_hat.author)] + g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.id.in_(owned_hat_ids), HatDef.id != v.equipped_hat_id).order_by(HatDef.price, HatDef.name).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()
|
||||
|
||||
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
|
||||
|
||||
return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v)
|
||||
|
||||
@app.post("/buy_hat/<hat_id>")
|
||||
@auth_required
|
||||
|
|
|
@ -38,27 +38,7 @@
|
|||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for hat, user in owned %}
|
||||
<tr>
|
||||
<td><img loading="lazy" alt="{{hat.name}}" src="/i/hats/{{hat.name}}.webp?v=1"></td>
|
||||
<td>{{hat.name}}</td>
|
||||
<td>{{hat.censored_description(v)}}</td>
|
||||
{% if SITE == 'rdrama.net' %}
|
||||
<td><a style="color:#{{user.name_color}}" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.name_color}}"{% endif %}>{{user.username}}</span></a></td>
|
||||
{% endif %}
|
||||
<td>{{hat.number_sold}}</td>
|
||||
<td>{{hat.price}}</td>
|
||||
<td class="shop-table-actions">
|
||||
{% if hat.id == v.equipped_hat.id %}
|
||||
<a id="unequip-{{hat.id}}" class="unequip btn btn-success" role="button" onclick="post_toast(this,'/unequip_hat',true)"><span class="m-auto">Unequip</span></a>
|
||||
{% else %}
|
||||
<a id="equip-{{hat.id}}" class="equip btn btn-success" role="button" onclick="post_toast(this,'/equip_hat/{{hat.id}}',true)"><span class="m-auto">Equip</span></a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
{% for hat, user in not_owned %}
|
||||
{% for hat, user in hats %}
|
||||
<tr>
|
||||
<td><img loading="lazy" alt="{{hat.name}}" src="/i/hats/{{hat.name}}.webp?v=1"></td>
|
||||
<td>{{hat.name}}</td>
|
||||
|
@ -69,15 +49,27 @@
|
|||
<td>{{hat.number_sold}}</td>
|
||||
<td>{{hat.price}}</td>
|
||||
<td class="shop-table-actions">
|
||||
{% if hat.id not in owned_hat_ids %}
|
||||
<div id="if-not-owned-{{hat.id}}">
|
||||
<a id="buy1-{{hat.id}}" class="btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy1-go-{{hat.id}}').classList.remove('d-none')"><span class="m-auto">Buy</span></a>
|
||||
|
||||
<a id="buy1-go-{{hat.id}}" class="d-none btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this,'/buy_hat/{{hat.id}}',true)"><span class="m-auto">Are you sure?</span></a>
|
||||
<a id="buy1-go-{{hat.id}}" class="d-none btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this, '/buy_hat/{{hat.id}}', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none')"><span class="m-auto">Are you sure?</span></a>
|
||||
|
||||
{% if FEATURES['PROCOINS'] %}
|
||||
<a id="buy2-{{hat.id}}" class="marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy2-go-{{hat.id}}').classList.remove('d-none')"><span class="m-auto">Buy with MBux</span></a>
|
||||
|
||||
<a id="buy2-go-{{hat.id}}" class="d-none marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this,'/buy_hat/{{hat.id}}?mb=true',true)"><span class="m-auto">Are you sure?</span></a>
|
||||
<a id="buy2-go-{{hat.id}}" class="d-none marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this, '/buy_hat/{{hat.id}}?mb=true', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none')"><span class="m-auto">Are you sure?</span></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="if-owned-{{hat.id}}" {% if hat.id not in owned_hat_ids %}class="d-none"{% endif %}>
|
||||
{% if hat.id == v.equipped_hat.id %}
|
||||
<a class="unequip btn btn-success" role="button" onclick="post_toast(this,'/unequip_hat', true)"><span class="m-auto">Unequip</span></a>
|
||||
{% else %}
|
||||
<a class="equip btn btn-success" role="button" onclick="post_toast(this,'/equip_hat/{{hat.id}}', true)"><span class="m-auto">Equip</span></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Reference in New Issue