Skip to content

Commit

Permalink
Change attachment to file response
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Nov 11, 2023
1 parent 9e3bb12 commit f525f57
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ def my_solution(self, request, pk=None):
raise exceptions.NotFound(
detail='Zatiaľ nebolo nahraté žiadne riešenie')
return FileResponse(
file, content_type='application/pdf')
file, content_type='application/pdf',
)

@action(detail=True, url_path='corrected-solution')
def corrected_solution(self, request, pk=None):
Expand Down Expand Up @@ -492,19 +493,25 @@ def remove_vote(self, request, pk=None):
def download_solution(self, request, pk=None):
"""Stiahne riešenie"""
solution = self.get_object()
response = HttpResponse(
solution.solution, content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{solution.solution}"'
return response
file = solution.solution
if not file:
raise exceptions.NotFound(
detail='Zatiaľ nebolo nahraté žiadne riešenie')
return FileResponse(
file, content_type='application/pdf',
)

@action(methods=['get'], detail=True, url_path='download-corrected')
def download_corrected(self, request, pk=None):
"""Stiahne opravenú verziu riešenia"""
solution = self.get_object()
response = HttpResponse(
solution.solution, content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{solution.corrected_solution}"'
return response
file = solution.corrected_solution
if not file:
raise exceptions.NotFound(
detail='Zatiaľ nebolo nahraté žiadne riešenie')
return FileResponse(
file, content_type='application/pdf',
)

@action(methods=['post'], detail=True,
url_path='upload-solution-file',
Expand Down

0 comments on commit f525f57

Please sign in to comment.