Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change attachment to file response #253

Merged
merged 3 commits into from
Nov 11, 2023
Merged
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
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
Loading