diff --git a/competition/views.py b/competition/views.py index 9420ba66..6bbb1ce0 100644 --- a/competition/views.py +++ b/competition/views.py @@ -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): @@ -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',