Skip to content

Commit

Permalink
Show currently selected donation tier in donate page
Browse files Browse the repository at this point in the history
  • Loading branch information
aahnik committed Jun 30, 2024
1 parent 5863e3d commit 40fa042
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/donations/templates/donations/donation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@
<h2 class="mb-4 text-xl font-bold text-gray-900 dark:text-white">
Make a donation
</h2>

{% if selected_tier %}
<div class="flex flex-col p-6 mx-auto max-w-lg text-center text-gray-900 bg-white rounded-lg border border-gray-100 shadow dark:border-gray-600 xl:p-8 dark:bg-gray-800 dark:text-white">
<h3 class="mb-4 text-2xl font-semibold">{{ selected_tier.name }}</h3>
<p class="font-light text-gray-500 sm:text-lg dark:text-gray-400">{{ selected_tier.description }}</p>
<div class="flex justify-center items-baseline my-8">
<span class="mr-2 text-5xl font-extrabold">₹ {{ selected_tier.amount }}</span>
</div>
<!-- List -->
<ul role="list" class="mb-8 space-y-4 text-center">
{% for tier_feature in selected_tier.tierfeature_set.all %}
<li class="text-center flex items-center space-x-3">
<!-- Icon -->
<svg class="flex-shrink-0 w-5 h-5 text-green-500 dark:text-green-400"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd">
</path>
</svg>
<span class="text-center">{{ tier_feature.feature }}</span>
</li>
{% endfor %}
</ul>

</div>

{% endif %}

<form method="post">
{% csrf_token %}

Expand Down
10 changes: 9 additions & 1 deletion src/donations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.")

Expand All @@ -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,
)

0 comments on commit 40fa042

Please sign in to comment.