diff --git a/beat/web/common/utils.py b/beat/web/common/utils.py index 122c25fab23df400415f6d54044677bf7a9f5be5..a2c5886e3123c01d0eb73e0d3d7e8e8531e85245 100644 --- a/beat/web/common/utils.py +++ b/beat/web/common/utils.py @@ -28,9 +28,9 @@ """ Reusable help functions """ - from django.core.exceptions import ValidationError from django.utils.encoding import force_text +from django.utils import six from ..ui.templatetags.markup import restructuredtext @@ -117,3 +117,14 @@ def ensure_html(text): return '<pre>{}</pre>'.format(text) else: return restructuredtext(text) + +def ensure_string(data): + """ + Ensure that we have a str object from data which can be either a str in + python 2 or a bytes in python 3 + """ + if data is not None: + if isinstance(data, six.binary_type): + return data.decode('utf-8') + return data + return '' \ No newline at end of file