Skip to content

Commit

Permalink
Adding file with email
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDyakonov committed Jun 16, 2024
1 parent ae7c30b commit b01f05f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/apps/mailer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .tasks import send_mail_with_attachment


def send_purchase_email(email, payment_id):
def send_purchase_email(email, payment_id, ticket_path):
order = Order.objects.filter(payment_id=payment_id).first()
qr_code_url = order.qr_code.url
context = {"order": {"qr_code": {"url": qr_code_url}}}
Expand All @@ -18,4 +18,4 @@ def send_purchase_email(email, payment_id):
"html_message": html_message,
}

send_mail_with_attachment([email], mail_data, "Ticket.pdf")
send_mail_with_attachment([email], mail_data, ticket_path)
2 changes: 0 additions & 2 deletions backend/apps/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from apps.amo.views import post_orders
from apps.booking.models import Booking, Buyer, Cart
from apps.booking.serializers import BookingSerializer, Buyer
from apps.mailer.utils import send_purchase_email
from apps.tickets.generator import generate_ticket
from apps.tickets.utils import get_ticket_info
from django.db import transaction
Expand Down Expand Up @@ -241,7 +240,6 @@ def yookassa_webhook(request):
post_orders([order])

if generate_ticket(get_ticket_info(payment_id), payment_id):
send_purchase_email(order.cart.buyer.email, payment_id)
return JsonResponse({"status": "success"}, status=200)
else:
return Response(
Expand Down
9 changes: 6 additions & 3 deletions backend/apps/tickets/generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import qrcode
from apps.mailer.utils import send_purchase_email
from apps.payments.models import Order
from django.core.files import File
from reportlab.lib.pagesizes import A4
Expand Down Expand Up @@ -32,7 +33,7 @@ def check_page_space(y_position, c, height):
return y_position


def generate_ticket(ticket_info, order_id):
def generate_ticket(ticket_info, payment_id):
try:
output_file = f"{ticket_info['output_file']}.pdf"

Expand Down Expand Up @@ -64,7 +65,7 @@ def generate_ticket(ticket_info, order_id):
y_position -= 60

# Генерация и вставка QR-кода
qr_code_path = f"qrcode_{order_id}.png"
qr_code_path = f"qrcode_{payment_id}.png"

generate_qr_code(ticket_info["qr_data"], qr_code_path)
c.drawImage(qr_code_path, width - 120, height - 120, width=100, height=100)
Expand Down Expand Up @@ -107,7 +108,9 @@ def generate_ticket(ticket_info, order_id):
c.showPage()
c.save()

order = Order.objects.filter(payment_id=order_id).first()
order = Order.objects.filter(payment_id=payment_id).first()

send_purchase_email(order.cart.buyer.email, payment_id, output_file)

with open(output_file, "rb") as f:
order.ticket_file.save(output_file, File(f))
Expand Down

0 comments on commit b01f05f

Please sign in to comment.