Skip to content

Commit

Permalink
Merge pull request #1912 from pik-software/context-manager
Browse files Browse the repository at this point in the history
forms.admin: add context manager
  • Loading branch information
stephenmcd authored Mar 18, 2019
2 parents 1196c75 + 8b5ad35 commit cf6c79c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mezzanine/forms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit cf6c79c

Please sign in to comment.