forked from rDrama/rDrama
make /hats more intuitive
parent
5feb479cd2
commit
5d704a2cb2
|
@ -11,11 +11,17 @@ from flask import g
|
||||||
def hats(v):
|
def hats(v):
|
||||||
if not FEATURES['HATS']: abort(404)
|
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_hat_ids = [x.hat_id for x in v.owned_hats]
|
||||||
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()
|
|
||||||
|
|
||||||
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>")
|
@app.post("/buy_hat/<hat_id>")
|
||||||
@auth_required
|
@auth_required
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for hat, user in owned %}
|
{% for hat, user in hats %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><img loading="lazy" alt="{{hat.name}}" src="/i/hats/{{hat.name}}.webp?v=1"></td>
|
<td><img loading="lazy" alt="{{hat.name}}" src="/i/hats/{{hat.name}}.webp?v=1"></td>
|
||||||
<td>{{hat.name}}</td>
|
<td>{{hat.name}}</td>
|
||||||
|
@ -49,35 +49,27 @@
|
||||||
<td>{{hat.number_sold}}</td>
|
<td>{{hat.number_sold}}</td>
|
||||||
<td>{{hat.price}}</td>
|
<td>{{hat.price}}</td>
|
||||||
<td class="shop-table-actions">
|
<td class="shop-table-actions">
|
||||||
{% if hat.id == v.equipped_hat.id %}
|
{% if hat.id not in owned_hat_ids %}
|
||||||
<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>
|
<div id="if-not-owned-{{hat.id}}">
|
||||||
{% else %}
|
<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="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>
|
|
||||||
|
<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', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none')"><span class="m-auto">Are you sure?</span></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for hat, user in not_owned %}
|
<div id="if-owned-{{hat.id}}" {% if hat.id not in owned_hat_ids %}class="d-none"{% endif %}>
|
||||||
<tr>
|
{% if hat.id == v.equipped_hat.id %}
|
||||||
<td><img loading="lazy" alt="{{hat.name}}" src="/i/hats/{{hat.name}}.webp?v=1"></td>
|
<a class="unequip btn btn-success" role="button" onclick="post_toast(this,'/unequip_hat', true)"><span class="m-auto">Unequip</span></a>
|
||||||
<td>{{hat.name}}</td>
|
{% else %}
|
||||||
<td>{{hat.censored_description(v)}}</td>
|
<a class="equip btn btn-success" role="button" onclick="post_toast(this,'/equip_hat/{{hat.id}}', true)"><span class="m-auto">Equip</span></a>
|
||||||
{% if SITE == 'rdrama.net' %}
|
{% endif %}
|
||||||
<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>
|
</div>
|
||||||
{% endif %}
|
|
||||||
<td>{{hat.number_sold}}</td>
|
|
||||||
<td>{{hat.price}}</td>
|
|
||||||
<td class="shop-table-actions">
|
|
||||||
<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>
|
|
||||||
|
|
||||||
{% 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>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in New Issue