diff --git a/annotations/annotators.py b/annotations/annotators.py index e7a85dfe..fb68c5ee 100644 --- a/annotations/annotators.py +++ b/annotations/annotators.py @@ -58,6 +58,7 @@ def my_view(request, text_id): from annotations.utils import basepath from annotations.models import TextCollection, VogonUserDefaultProject from urlparse import urlparse +import chardet class Annotator(object): @@ -153,11 +154,13 @@ def render_display(self, context={}): def get_context(self): resource = self.get_resource() request = self.context.get('request') + content = self.get_content(resource) + detect = chardet.detect(content) return { 'text': self.text, 'textid': self.text.id, 'title': 'Annotate Text', - 'content': self.get_content(resource), + 'content': content.decode(detect['encoding']).encode('utf-8'), # We are using chardet to guess the encoding becuase giles is returning everyting with a utf-8 header even if it is not utf-8 'baselocation' : basepath(request), 'userid': request.user.id, 'title': self.text.title, diff --git a/annotations/templates/annotations/vue.html b/annotations/templates/annotations/vue.html index 3e6dc76d..ea88c7d8 100644 --- a/annotations/templates/annotations/vue.html +++ b/annotations/templates/annotations/vue.html @@ -231,7 +231,7 @@ var USER_NAME = '{{ user.username }}'; var PROJECT_ID = '{{ project.id }}'; var PROJECT_NAME = '{{ project.name }}'; - var TEXT_CONTENT = `{{ content|safe }}`; + var TEXT_CONTENT = `{{ content|safe }}`; // the safe tag suppresses unicode errors var BASE_URL = '{{ base_url }}'; // Appellator is the text annotation application. Even though we load diff --git a/requirements.txt b/requirements.txt index 5ffd2911..f3cd6e7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,4 +39,5 @@ Unidecode==0.4.20 urllib3==1.19.1 xmltodict==0.10.2 dicttoxml==1.6.6 -six==1.10.0 \ No newline at end of file +six==1.10.0 +