Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions partner_programs/report_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import connection, transaction
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView

from core.utils import build_xlsx_download_response
from partner_programs.services.management import managed_program
from partner_programs.services.program_report import build_program_report


class ProgramReportView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request, pk):
with transaction.atomic():
if connection.vendor == "postgresql":
with connection.cursor() as cursor:
cursor.execute(
"SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY"
)
program = managed_program(pk, request.user)
data = build_program_report(program)
response = build_xlsx_download_response(
data, base_name=f"Программа - {program.name}"
)
response["Cache-Control"] = "private, no-store"
return response
Loading
Loading