Repository: fossasia/open-event-server

Issue:
Export json files without unicode escaping
Currently json files in export feature are exported in such a way that unicode chars are escaped. 
See json below for example. (see \u00e9 part) 

``` json
{
        "name": "Marco A. Guti\u00e9rrez", 
        "organisation": "Robolab, University of Extremadura, Spain", 
        "photo": "/images/speakers/MarcoA.Guti\u00e9rrez_130.jpg", 
}
```

We can export files in such a way that real unicode chars are printed instead of escaped ones. @mariobehling What do you think ?
I did some research and don't think it has any disadvantages. 



Discussion:
@aviaryan Yes, very good and it would also help to keep it human readable. Thank you.


Resolving patch:
diff --git a/app/api/helpers/export_helpers.py b/app/api/helpers/export_helpers.py
--- a/app/api/helpers/export_helpers.py
+++ b/app/api/helpers/export_helpers.py
@@ -177,12 +177,15 @@ def export_event_json(event_id, settings):
             for count in range(len(data)):
                 data[count] = _order_json(data[count], e)
                 _download_media(data[count], e[0], dir_path, settings)
-        data_str = json.dumps(data, indent=4)
+        data_str = json.dumps(data, indent=4, ensure_ascii=False).encode('utf-8')
         fp = open(dir_path + '/' + e[0], 'w')
         fp.write(data_str)
         fp.close()
     # add meta
-    data_str = json.dumps(_generate_meta(), sort_keys=True, indent=4)
+    data_str = json.dumps(
+        _generate_meta(), sort_keys=True,
+        indent=4, ensure_ascii=False
+    ).encode('utf-8')
     fp = open(dir_path + '/meta', 'w')
     fp.write(data_str)
     fp.close()


Test patch:
diff --git a/tests/api/test_export_import.py b/tests/api/test_export_import.py
--- a/tests/api/test_export_import.py
+++ b/tests/api/test_export_import.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 import unittest
 import json
 import logging
@@ -53,6 +55,8 @@ def _do_successful_export(self, event_id, config={'image': True}):
                 self.assertIn('download_url', resp.data)
                 dl = json.loads(resp.data)['result']['download_url']
                 break
+            if resp.status_code != 200:
+                self.assertTrue(False, 'Export fail')
             time.sleep(1)
         # get event
         resp = self.app.get(dl)
@@ -109,17 +113,24 @@ def test_export_no_event(self):
 
     def test_export_media(self):
         """
-        test successful export of media (and more)
+        test successful export of media, unicode and more
         """
         resp = self._put(get_path(1), {'logo': 'https://placehold.it/350x150'})
         self.assertIn('placehold', resp.data, resp.data)
         # set speaker photo so that its export is checked
         resp = self._put(get_path(1, 'speakers', 1), {'photo': 'https://placehold.it/350x150'})
+        # set event title as unicode
+        resp = self._put(get_path(1), {'organizer_name': 'SandraMüllrick'})
+        # export and unzip files
         self._create_set()
         dr = 'static/temp/test_event_import'
         data = open(dr + '/event', 'r').read()
         self.assertIn('images/logo', data)
-        self.assertEqual(json.loads(data)['creator'].get('id'), None)  # test no ID of creator
+        # test unicode in file
+        self.assertIn('ü', data)
+        self.assertNotIn('\u', data)  # unicode escape
+        # test no ID of creator
+        self.assertEqual(json.loads(data)['creator'].get('id'), None)
         obj = json.loads(data)
         logo_data = open(dr + obj['logo'], 'r').read()
         self.assertTrue(len(logo_data) > 10)