Formalize unpurchasable hats.

remotes/1693045480750635534/spooky-22
Snakes 2022-10-31 23:37:52 -04:00
parent 18b6bd6b2d
commit 8f324c923e
Signed by: Snakes
GPG Key ID: E745A82778055C7E
3 changed files with 9 additions and 3 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,8 +45,8 @@ 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 hat.price == 0 and v.id != CARP_ID: #### TEMP HOMOWEEN
abort(403, "Only Carp can buy that 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)

View File

@ -122,7 +122,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}}">
<a id="buy1-{{hat.id}}" class="btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" data-click="post_toast(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></a>