1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-25 10:20:30 +02:00

Create payments in a signal rather than in a view

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-02-24 09:39:04 +01:00
parent 9380fbaaf7
commit 6e35bdc0b3
3 changed files with 43 additions and 20 deletions

View File

@ -249,20 +249,6 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
mail_html = render_to_string("participation/mails/team_validated.html", mail_context)
send_mail("[TFJM²] Équipe validée", mail_plain, None, [self.object.email], html_message=mail_html)
for student in self.object.students.all():
payment_qs = Payment.objects.filter(registrations=student)
if payment_qs.exists():
payment = payment_qs.get()
else:
payment = Payment.objects.create()
payment.registrations.add(student)
payment.save()
payment.amount = self.object.participation.tournament.price
if payment.amount == 0:
payment.type = "free"
payment.valid = True
payment.save()
elif "invalidate" in self.request.POST:
self.object.participation.valid = None
self.object.participation.save()