From 8f324c923e2543198a017cc8fd51af954d47b633 Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 31 Oct 2022 23:37:52 -0400 Subject: [PATCH] Formalize unpurchasable hats. --- files/classes/hats.py | 6 ++++++ files/routes/hats.py | 4 ++-- files/templates/hats.html | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/files/classes/hats.py b/files/classes/hats.py index 5a1849971..b7c778563 100644 --- a/files/classes/hats.py +++ b/files/classes/hats.py @@ -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" diff --git a/files/routes/hats.py b/files/routes/hats.py index ca5d2501e..6e5644680 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -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) diff --git a/files/templates/hats.html b/files/templates/hats.html index 99a9d9409..5b5744f57 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -122,7 +122,7 @@ {{hat.number_sold}} {{hat.price}} - {% if hat.id not in owned_hat_ids %} + {% if hat.id not in owned_hat_ids and hat.is_purchasable %}
Buy