From 8b5ad35ec1799729369d5da094cc5adfd86b3e17 Mon Sep 17 00:00:00 2001 From: MaximZemskov Date: Mon, 18 Mar 2019 20:33:33 +0300 Subject: [PATCH] forms.admin: add context manager --- mezzanine/forms/admin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mezzanine/forms/admin.py b/mezzanine/forms/admin.py index dc5d8a93c0..7fb12a054d 100644 --- a/mezzanine/forms/admin.py +++ b/mezzanine/forms/admin.py @@ -169,10 +169,10 @@ def file_view(self, request, field_entry_id): field_entry = get_object_or_404(FieldEntry, id=field_entry_id) path = join(fs.location, field_entry.value) response = HttpResponse(content_type=guess_type(path)[0]) - f = open(path, "r+b") - response["Content-Disposition"] = "attachment; filename=%s" % f.name - response.write(f.read()) - f.close() + with open(path, "r+b") as f: + response["Content-Disposition"] = ("attachment; filename=%s" + % f.name) + response.write(f.read()) return response admin.site.register(Form, FormAdmin)