Skip to content

Commit

Permalink
Merge pull request #253 from ZdruzenieSTROM/file_response_for_solution
Browse files Browse the repository at this point in the history
Change attachment to file response
  • Loading branch information
kovacspe authored Nov 11, 2023
2 parents 9e3bb12 + e4275d2 commit 4a51089
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,23 +488,29 @@ def remove_vote(self, request, pk=None):
self.get_object().set_vote(Vote.NONE)
return Response('Hlas Odobraný.', status=status.HTTP_200_OK)

@action(methods=['get'], detail=True, url_path='download-solution')
def download_solution(self, request, pk=None):
@action(methods=['get'], detail=True, url_path='file-solution')
def file_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):
@action(methods=['get'], detail=True, url_path='file-corrected')
def file_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 4a51089

Please sign in to comment.