From e1e1628cafaddf0e9c081991b36fe7c903dbf9c5 Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Sun, 13 Oct 2024 09:08:02 +0200 Subject: [PATCH] fixes --- alkatorapi/views.py | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/alkatorapi/views.py b/alkatorapi/views.py index 4e9f58e..4b53f5d 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -241,10 +241,11 @@ def payment_result(request): if paid == 'PAID': invoice.paid = True invoice.save() - racer = Racer.objects.get(invoice=invoice) - mail = EmailMessage( - subject=f"úspěšná registrace do závodu Alkátor race Dolní Čermná ({racer.first_name} {racer.last_name})", - body=f"""Zdravím tě Alkátore, + try: + racer = Racer.objects.get(invoice=invoice) + mail = EmailMessage( + subject=f"úspěšná registrace do závodu Alkátor race Dolní Čermná ({racer.first_name} {racer.last_name})", + body=f"""Zdravím tě Alkátore, toto je potvrzovací email o účasti v nezapomenutelném závodě Alkátor-race. Prosíme kontrolujete si své hromadné schránky a spamy. @@ -263,11 +264,30 @@ ALKÁTOR TEAM email: info@alkator.cz tel: + 420 728 018 088 web: https://alkator.cz""", - from_email="info@alkator.cz", - to=[racer.profile.user.email, racer.email] if racer.email else [racer.profile.user.email], - bcc=["info@alkator.cz"], - cc=[] - ) + from_email="info@alkator.cz", + to=[racer.profile.user.email, racer.email] if racer.email else [racer.profile.user.email], + bcc=["info@alkator.cz"], + cc=[] + ) + except Racer.DoesNotExist: + mail = EmailMessage( + subject=f"úspěšně zaplacený nákup v Alkátor shopu", + body=f"""Zdravím tě Alkátore, + +úspěšně si zakoupil merch na Alkátor shopu. + +Na tento email není třeba odpovídat, protože je generován automaticky s přijatou platbou. V případě potřeby pište na info@alkator.cz . + +ALKÁTOR TEAM +email: info@alkator.cz +tel: + 420 728 018 088 +web: https://alkator.cz""", + from_email="info@alkator.cz", + to=[racer.profile.user.email, racer.email] if racer.email else [racer.profile.user.email], + bcc=["info@alkator.cz"], + cc=[] + ) + return HttpResponse(status=200) user = invoice.user @@ -278,11 +298,11 @@ web: https://alkator.cz""", 'user': user, 'invoice': invoice, 'products': InvoiceProduct.objects.filter(invoice=invoice), - 'paid_date': racer.register_date + timedelta(days=1), + 'paid_date': invoice.paid_date + timedelta(days=1), } ) template.render() - pdf_name = f"invoices/{user.profile.last_name}_{user.profile.first_name}.pdf" + pdf_name = f"invoices/{invoice.invoice_id}_{user.profile.last_name}_{user.profile.first_name}.pdf" HTML(string=template.content).write_pdf(pdf_name) attach = open(pdf_name, 'rb') @@ -290,7 +310,10 @@ web: https://alkator.cz""", if not mail.send(): return HttpResponse(status=500) elif paid == 'CANCELLED' and not user.paid: + racer.product.quantity += 1 + racer.product.save() racer.delete() + invoice.delete() return HttpResponse(status=200)