PDF editor: Catch ValueError during float conversion

This commit is contained in:
Raphael Michel
2019-09-30 14:36:50 +02:00
parent 4e58ba7594
commit 9e85d3c94c

View File

@@ -123,10 +123,16 @@ class BaseEditorView(EventPermissionRequiredMixin, TemplateView):
def post(self, request, *args, **kwargs):
if "emptybackground" in request.POST:
p = PdfFileWriter()
p.addBlankPage(
width=float(request.POST.get('width')) * mm,
height=float(request.POST.get('height')) * mm,
)
try:
p.addBlankPage(
width=float(request.POST.get('width')) * mm,
height=float(request.POST.get('height')) * mm,
)
except ValueError:
return JsonResponse({
"status": "error",
"error": "Invalid height/width given."
})
buffer = BytesIO()
p.write(buffer)
buffer.seek(0)