SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit beed83a1 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

fix(graphs): :goal: catch download of empty figure

parent f6722b20
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ __license__ = "AGPL v3" ...@@ -4,6 +4,7 @@ __license__ = "AGPL v3"
import io import io
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.http import Http404
from django.shortcuts import HttpResponse, render from django.shortcuts import HttpResponse, render
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
...@@ -77,6 +78,9 @@ class PlotView(View): ...@@ -77,6 +78,9 @@ class PlotView(View):
figure = self.render_figure() figure = self.render_figure()
bytes_io = io.BytesIO() bytes_io = io.BytesIO()
if figure is None:
raise Http404("No figure exists with the given options")
match file_type: match file_type:
case "svg": case "svg":
figure.savefig(bytes_io, format="svg") figure.savefig(bytes_io, format="svg")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment