Files
NexHome/price_pref.py
T
Black-Cyan 9e9788ea22 🛠️
- add show price preference(store in cookies)
2026-06-12 17:36:57 +08:00

20 lines
560 B
Python

VALID_PRICE_PREFS = ("total", "sqft", "both")
def get_price_pref(request) -> str:
pref = request.cookies.get("price_pref", "total")
if pref not in VALID_PRICE_PREFS:
pref = "total"
return pref
def format_price(value: int, price_pref: str = "total", area_sqft: int = 0) -> str:
if area_sqft > 0:
unit_price = round(value / area_sqft)
if price_pref == "sqft":
return f"${unit_price:,}/sqft"
if price_pref == "both":
return f"${value:,} (${unit_price:,}/sqft)"
return f"${value:,}"