Repository: learningequality/kolibri

Issue:
Resources loading on Windows (follow-up from #8159)

## Observed behavior
After Promise.polyfill issue was fixed to restore IE11 compatibility in #8159, resources (HTML5, videos) are not loading on all browsers on Windows, but those on Ubuntu Linux are not affected.

HTML on IE11 | HTML on Firefox | videos on FF &  Chrome
--- | --- | --- 
![Win7 (start)  Running  - Oracle VM VirtualBox_039](https://user-images.githubusercontent.com/1457929/122480445-2ae79f00-cfcd-11eb-9cdf-70c5eb78bdfe.jpg) | ![Win7 (start)  Running  - Oracle VM VirtualBox_040](https://user-images.githubusercontent.com/1457929/122480490-3aff7e80-cfcd-11eb-877c-634961f72953.jpg) | ![Win7 (start)  Running  - Oracle VM VirtualBox_041](https://user-images.githubusercontent.com/1457929/122480548-536f9900-cfcd-11eb-8d28-45ebd1a9dc0b.jpg) <br> ![Win7 (start)  Running  - Oracle VM VirtualBox_042](https://user-images.githubusercontent.com/1457929/122480570-5ff3f180-cfcd-11eb-8cb1-b806e5abede3.jpg)

## Errors and logs
…

## Expected behavior
Resources loading correctly on IE11, Firefox and Chrome on Windows.

## User-facing consequences
...

## Steps to reproduce
…

## Context
 * Kolibri version: 0.15/develop
 * Operating system: Windows 7
 * Browser: all

cc @rtibbles 



Discussion:

Resolving patch:
diff --git a/kolibri/utils/kolibri_whitenoise.py b/kolibri/utils/kolibri_whitenoise.py
--- a/kolibri/utils/kolibri_whitenoise.py
+++ b/kolibri/utils/kolibri_whitenoise.py
@@ -5,6 +5,7 @@
 
 from django.contrib.staticfiles import finders
 from django.core.files.storage import FileSystemStorage
+from django.utils._os import safe_join
 from whitenoise import WhiteNoise
 from whitenoise.string_utils import decode_path_info
 
@@ -25,9 +26,6 @@ def __init__(self, locations):
             raise TypeError("locations argument is not a tuple or list")
         for root in locations:
             prefix, root = root
-            # Django requires paths, even on Windows, to use forward slashes
-            # do this substitution that will be idempotent on Unix
-            root = root.replace(os.sep, "/")
             if not prefix:
                 raise ValueError(
                     "Cannot use unprefixed locations for dynamic locations"
@@ -42,9 +40,20 @@ def __init__(self, locations):
             filesystem_storage.prefix = prefix
             self.storages[root] = filesystem_storage
 
-    def find(self, path, all=False):
-        path = path.replace("/", os.sep)
-        return super(FileFinder, self).find(path, all=all)
+    def find_location(self, root, path, prefix=None):
+        """
+        Finds a requested static file in a location, returning the found
+        absolute path (or ``None`` if no match).
+        Vendored from Django to handle being passed a URL path instead of a file path.
+        """
+        if prefix:
+            prefix = prefix + "/"
+            if not path.startswith(prefix):
+                return None
+            path = path[len(prefix) :]
+        path = safe_join(root, path)
+        if os.path.exists(path):
+            return path
 
 
 class DynamicWhiteNoise(WhiteNoise):


Test patch:
diff --git a/kolibri/utils/tests/test_kolibri_whitenoise.py b/kolibri/utils/tests/test_kolibri_whitenoise.py
--- a/kolibri/utils/tests/test_kolibri_whitenoise.py
+++ b/kolibri/utils/tests/test_kolibri_whitenoise.py
@@ -10,7 +10,7 @@
 def test_file_finder():
     tempdir1 = tempfile.mkdtemp()
     tempdir2 = tempfile.mkdtemp()
-    prefix = "test"
+    prefix = "/test"
     tempdir1tempfile, tempdir1tempfilepath = tempfile.mkstemp(dir=tempdir1)
     tempdir2tempfile, tempdir2tempfilepath = tempfile.mkstemp(dir=tempdir2)
     tempdir1tempfilename = os.path.basename(tempdir1tempfilepath)
@@ -30,14 +30,14 @@ def test_file_finder():
 def test_dynamic_whitenoise():
     tempdir11 = tempfile.mkdtemp()
     tempdir12 = tempfile.mkdtemp()
-    prefix1 = "test"
+    prefix1 = "/test"
     tempdir11tempfile, tempdir11tempfilepath = tempfile.mkstemp(dir=tempdir11)
     tempdir12tempfile, tempdir12tempfilepath = tempfile.mkstemp(dir=tempdir12)
     tempdir11tempfilename = os.path.basename(tempdir11tempfilepath)
     tempdir12tempfilename = os.path.basename(tempdir12tempfilepath)
     tempdir21 = tempfile.mkdtemp()
     tempdir22 = tempfile.mkdtemp()
-    prefix2 = "notatest"
+    prefix2 = "/notatest"
     tempdir21tempfile, tempdir21tempfilepath = tempfile.mkstemp(dir=tempdir21)
     tempdir22tempfile, tempdir22tempfilepath = tempfile.mkstemp(dir=tempdir22)
     tempdir21tempfilename = os.path.basename(tempdir21tempfilepath)