From 40fa042d2a480369eacccbb9dac5715fa895d999 Mon Sep 17 00:00:00 2001 From: aahnik Date: Sun, 30 Jun 2024 23:12:21 +0530 Subject: [PATCH] Show currently selected donation tier in donate page --- .../templates/donations/donation_form.html | 29 +++++++++++++++++++ src/donations/views.py | 10 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/donations/templates/donations/donation_form.html b/src/donations/templates/donations/donation_form.html index 390f892..99b7534 100644 --- a/src/donations/templates/donations/donation_form.html +++ b/src/donations/templates/donations/donation_form.html @@ -12,6 +12,35 @@

Make a donation

+ + {% if selected_tier %} +
+

{{ selected_tier.name }}

+

{{ selected_tier.description }}

+
+ ₹ {{ selected_tier.amount }} +
+ + + +
+ + {% endif %} +
{% csrf_token %} diff --git a/src/donations/views.py b/src/donations/views.py index b59cde6..061eafa 100644 --- a/src/donations/views.py +++ b/src/donations/views.py @@ -121,6 +121,7 @@ def get_callback_url(request: HttpRequest): def make_donation(request: HttpRequest): + context = {} if request.method == "POST": form = DonationForm(request.POST) if form.is_valid(): @@ -167,6 +168,7 @@ def make_donation(request: HttpRequest): if tier_id is not None: try: donation_tier = DonationTier.objects.get(id=tier_id) + context["selected_tier"] = donation_tier except DonationTier.DoesNotExist: raise Http404("This donation tier does not exist. Try again.") @@ -177,4 +179,10 @@ def make_donation(request: HttpRequest): } ) form = DonationForm(initial=pre_filled_data) - return render(request, "donations/donation_form.html", {"form": form}) + + context["form"] = form + return render( + request, + "donations/donation_form.html", + context=context, + )