Save Excel and PDF to AWS S3.
This commit is contained in:
16
rog/views.py
16
rog/views.py
@ -17,7 +17,7 @@ import requests
|
||||
from rest_framework import serializers
|
||||
from django.db import IntegrityError
|
||||
from django.urls import reverse
|
||||
from .utils import send_verification_email,send_invitation_email,send_team_join_email,send_reset_password_email
|
||||
from .utils import S3Bucket, send_verification_email,send_invitation_email,send_team_join_email,send_reset_password_email
|
||||
from django.conf import settings
|
||||
import uuid
|
||||
from rest_framework.exceptions import ValidationError as DRFValidationError
|
||||
@ -2817,13 +2817,15 @@ def export_excel(request, zekken_number, event_code):
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
|
||||
# PDFファイルを読み込んでレスポンスを返す
|
||||
with open(pdf_path, 'rb') as pdf_file:
|
||||
pdf_content = pdf_file.read()
|
||||
s3 = S3Bucket('sumasenrogaining')
|
||||
s3.upload_file(pdf_path, f'{event_code}/scoreboard', f'certificate_{zekken_number}.pdf')
|
||||
s3.upload_file(excel_path, f'{event_code}/scoreboard_excel', f'certificate_{zekken_number}.xlsx')
|
||||
|
||||
os.remove(excel_path)
|
||||
os.remove(pdf_path)
|
||||
|
||||
return Response( status=status.HTTP_200_OK )
|
||||
|
||||
response = HttpResponse(pdf_content, content_type='application/pdf')
|
||||
response['Content-Disposition'] = f'attachment; filename="certificate_{zekken_number}_{event_code}.pdf"'
|
||||
return response
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"Error converting to PDF: {str(e)}\nSTDOUT: {e.stdout}\nSTDERR: {e.stderr}")
|
||||
|
||||
Reference in New Issue
Block a user