Author photos and nicer Wikidata imports.
[redakcja.git] / src / fileupload / views.py
index 3e6b999..23fbc3b 100644 (file)
@@ -1,3 +1,6 @@
+# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 import json
 import os
 from urllib.parse import quote
 import json
 import os
 from urllib.parse import quote
@@ -95,7 +98,7 @@ class UploadView(FormView):
         return super(UploadView, self).dispatch(request, *args, **kwargs)
 
     def get(self, request, *args, **kwargs):
         return super(UploadView, self).dispatch(request, *args, **kwargs)
 
     def get(self, request, *args, **kwargs):
-        if request.is_ajax():
+        if request.headers.get('x-requested-with') == 'XMLHttpRequest':
             files = []
             path = self.get_safe_path()
             if os.path.isdir(path):
             files = []
             path = self.get_safe_path()
             if os.path.isdir(path):
@@ -129,7 +132,7 @@ class UploadView(FormView):
             os.makedirs(path)
         data = []
         for f in flist:
             os.makedirs(path)
         data = []
         for f in flist:
-            with open(self.get_safe_path(f.name), 'w') as destination:
+            with open(self.get_safe_path(f.name), 'wb') as destination:
                 for chunk in f.chunks():
                     destination.write(chunk)
             data.append({
                 for chunk in f.chunks():
                     destination.write(chunk)
             data.append({