Skip to content

Commit cf6c79c

Browse files
authored
Merge pull request stephenmcd#1912 from pik-software/context-manager
forms.admin: add context manager
2 parents 1196c75 + 8b5ad35 commit cf6c79c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mezzanine/forms/admin.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ def file_view(self, request, field_entry_id):
169169
field_entry = get_object_or_404(FieldEntry, id=field_entry_id)
170170
path = join(fs.location, field_entry.value)
171171
response = HttpResponse(content_type=guess_type(path)[0])
172-
f = open(path, "r+b")
173-
response["Content-Disposition"] = "attachment; filename=%s" % f.name
174-
response.write(f.read())
175-
f.close()
172+
with open(path, "r+b") as f:
173+
response["Content-Disposition"] = ("attachment; filename=%s"
174+
% f.name)
175+
response.write(f.read())
176176
return response
177177

178178
admin.site.register(Form, FormAdmin)

0 commit comments

Comments
 (0)