Live update basket price in title

This commit is contained in:
Gabriel Augendre 2023-03-27 17:57:46 +02:00
parent 2d952e1a63
commit a219eeae84
2 changed files with 6 additions and 3 deletions

View file

@ -6,7 +6,7 @@
{% endblock %}
{% block content %}
{% if basket %}
<h1>{{ basket }} <span class="badge bg-secondary">{{ basket.price|currency }}</span></h1>
<h1>{{ basket }} <span id="basket-price" class="badge bg-secondary">{{ basket.price|currency }}</span></h1>
<p class="metadata">
{{ basket.created_at }}
</p>
@ -14,7 +14,7 @@
<div class="alert alert-danger" role="alert">{% translate "Missing payment method." %}</div>
{% endif %}
{% else %}
<h1>{% translate "New basket" %}</h1>
<h1>{% translate "New basket" %} <span id="basket-price" class="badge bg-secondary d-none">{{ basket.price|currency }}</span></h1>
{% endif %}
{% crispy form %}
<div class="row">

View file

@ -129,4 +129,7 @@ def price_preview(request: WSGIRequest) -> HttpResponse:
elif name.startswith(UNPRICED_PREFIX):
total += sum(map(int, request.POST.getlist(name)))
return HttpResponse(f"Montant total : {total/100:.2f}")
total = f"{total/100:.2f}"
return HttpResponse(
f'<span hx-swap-oob="true" id="basket-price" class="badge bg-secondary">{total}</span>Montant total : {total}',
)