Skip to content
Snippets Groups Projects
Commit eb2e9d80 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[ui][widgets][CodeMirrorFileWidget] Decode content read if bytes

If the data returned by the read method of the
object passed is byte, decode it. Otherwise
the TextArea will just show it as is.
parent 2caa80b6
No related branches found
No related tags found
2 merge requests!351Fix forms,!342Django 3 migration
......@@ -346,6 +346,8 @@ class CodeMirrorFileWidget(CodeMirrorTextarea):
contents = value
elif hasattr(value, "read"):
contents = value.read()
if type(contents) == bytes:
contents = contents.decode("utf-8")
else:
contents = ""
return mark_safe(super().render(name, contents, attrs, renderer)) # nosec
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