Repository: zestedesavoir/zds-site

Issue:
Erreur d’encodage lorsque l’on publie un document avec un titre Unicode
- Mettez une locale (moisie) en US-ASCII
- Allez sur la branche `dev`.
- Créez un billet avec “bépo” comme titre
- Publiez !

```
back_1           | Internal Server Error: /billets/36/bpeo-2/
back_1           | Traceback (most recent call last):
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 42, in inner
back_1           |     response = get_response(request)
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
back_1           |     response = self._get_response(request)
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
back_1           |     response = self.process_exception_by_middleware(e, request)
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
back_1           |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py", line 68, in view
back_1           |     return self.dispatch(request, *args, **kwargs)
back_1           |   File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py", line 88, in dispatch
back_1           |     return handler(request, *args, **kwargs)
back_1           |   File "/zds/zds/tutorialv2/mixins.py", line 433, in get
back_1           |     self.versioned_object = self.get_versioned_object()
back_1           |   File "/zds/zds/tutorialv2/mixins.py", line 405, in get_versioned_object
back_1           |     return self.public_content_object.load_public_version_or_404()
back_1           |   File "/zds/zds/tutorialv2/models/models_database.py", line 651, in load_public_version_or_404
back_1           |     self.versioned_model = self.content.load_version_or_404(sha=self.sha_public, public=self)
back_1           |   File "/zds/zds/tutorialv2/models/models_database.py", line 321, in load_version_or_404
back_1           |     return self.load_version(sha, public)
back_1           |   File "/zds/zds/tutorialv2/models/models_database.py", line 363, in load_version
back_1           |     json = json_reader.loads(manifest.read())
back_1           |   File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
back_1           |     return codecs.ascii_decode(input, self.errors)[0]
back_1           | UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 67: ordinal not in range(128)
```

Il est bien possible qu’il n’y ai pas de problème avec une locale en UTF-8, mais j’ai ouï dire que changer la locale sous Windows posait bien des problèmes.


Discussion:

Resolving patch:
diff --git a/zds/tutorialv2/models/models_database.py b/zds/tutorialv2/models/models_database.py
--- a/zds/tutorialv2/models/models_database.py
+++ b/zds/tutorialv2/models/models_database.py
@@ -357,10 +357,16 @@ def load_version(self, sha=None, public=None):
             if sha != public.sha_public:
                 raise NotAPublicVersion
 
-            manifest = open(os.path.join(path, 'manifest.json'), 'r')
-            json = json_reader.loads(manifest.read())
-            versioned = get_content_from_json(
-                json, public.sha_public, slug, public=True, max_title_len=max_title_length, hint_licence=self.licence)
+            with open(os.path.join(path, 'manifest.json'), 'r', encoding='utf-8') as manifest:
+                json = json_reader.loads(manifest.read())
+                versioned = get_content_from_json(
+                    json,
+                    public.sha_public,
+                    slug,
+                    public=True,
+                    max_title_len=max_title_length,
+                    hint_licence=self.licence,
+                )
 
         else:  # draft version, use the repository (slower, but allows manipulation)
             path = self.get_repo_path()


Test patch: