forked from rDrama/rDrama
1
0
Fork 0

Formalize unpurchasable hats.

master
Snakes 2022-10-31 23:37:52 -04:00
parent bfb13e9fec
commit d7aaa33c7f
Signed by: Snakes
GPG Key ID: E745A82778055C7E
3 changed files with 10 additions and 1 deletions

View File

@ -36,6 +36,12 @@ class HatDef(Base):
def censored_description(self, v):
return censor_slurs(self.description, v)
@property
@lazy
def is_purchasable(self):
return self.price > 0
class Hat(Base):
__tablename__ = "hats"

View File

@ -45,6 +45,9 @@ def buy_hat(v, hat_id):
existing = g.db.query(Hat).filter_by(user_id=v.id, hat_id=hat.id).one_or_none()
if existing: abort(400, "You already own this hat!")
if not hat.is_purchasable:
abort(403, "This hat is not for sale.")
if request.values.get("mb"):
charged = v.charge_account('procoins', hat.price)
if not charged: abort(400, "Not enough marseybux.")

View File

@ -120,7 +120,7 @@
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold}}</a></td>
<td>{{hat.price}}</td>
<td class="shop-table-actions" style="width:unset">
{% if hat.id not in owned_hat_ids %}
{% if hat.id not in owned_hat_ids and hat.is_purchasable %}
<div id="if-not-owned-{{hat.id}}">
<button type="button" id="buy1-{{hat.id}}" class="btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" data-click="postToast(this, '/buy_hat/{{hat.id}}', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none', (xhr)=>{if(xhr.status == 200)document.getElementById('user-coins-amount').innerHTML-={{hat.price}}})" onclick="areyousure(this)"><span class="m-auto">Buy</span></button>