Repository: learningequality/kolibri

Issue:
after triggering a CSV export and generating the file, nothing happens

### Observed behavior

File generates but does not download

![2020-07-01 08 51 39](https://user-images.githubusercontent.com/2367265/86265469-aa8c1c00-bb78-11ea-84a7-11c42c35ca35.gif)


### Expected behavior

File should begin downloading after generation is complete as it does in the PF branch:

![2020-07-01 08 55 30](https://user-images.githubusercontent.com/2367265/86265491-aeb83980-bb78-11ea-98ff-c80ea480c356.gif)


### Context

0.14.0 beta 7


Discussion:

Resolving patch:
diff --git a/kolibri/core/tasks/api.py b/kolibri/core/tasks/api.py
--- a/kolibri/core/tasks/api.py
+++ b/kolibri/core/tasks/api.py
@@ -675,9 +675,22 @@ def exportuserstocsv(self, request):
         """
         Export users, classes, roles and roles assignemnts to a csv file.
 
+        :param: facility_id
         :returns: An object with the job information
+
         """
-        facility = request.user.facility.id
+        facility_id = request.data.get("facility_id", None)
+
+        try:
+            if facility_id:
+                facility = Facility.objects.get(pk=facility_id).id
+            else:
+                facility = request.user.facility
+        except Facility.DoesNotExist:
+            raise serializers.ValidationError(
+                "Facility with ID {} does not exist".format(facility_id)
+            )
+
         job_type = "EXPORTUSERSTOCSV"
         job_metadata = {
             "type": job_type,
@@ -707,6 +720,7 @@ def startexportlogcsv(self, request):
         By default it will be dump contentsummarylog.
 
         :param: logtype: Kind of log to dump, summary or session
+        :param: facility
         :returns: An object with the job information
 
         """
diff --git a/kolibri/plugins/facility/api_urls.py b/kolibri/plugins/facility/api_urls.py
--- a/kolibri/plugins/facility/api_urls.py
+++ b/kolibri/plugins/facility/api_urls.py
@@ -4,7 +4,7 @@
 
 urlpatterns = [
     url(
-        r"^downloadcsvfile/(?P<filename>.*)/$",
+        r"^downloadcsvfile/(?P<filename>.*)/(?P<facility_id>.*)$",
         download_csv_file,
         name="download_csv_file",
     )
diff --git a/kolibri/plugins/facility/views.py b/kolibri/plugins/facility/views.py
--- a/kolibri/plugins/facility/views.py
+++ b/kolibri/plugins/facility/views.py
@@ -15,6 +15,7 @@
 from django.utils.translation import pgettext
 from django.views.generic.base import TemplateView
 
+from kolibri.core.auth.models import Facility
 from kolibri.core.decorators import cache_no_user_data
 from kolibri.utils import conf
 
@@ -24,7 +25,12 @@ class FacilityManagementView(TemplateView):
     template_name = "facility_management.html"
 
 
-def download_csv_file(request, filename):
+def download_csv_file(request, filename, facility_id):
+    if facility_id:
+        facility_name = Facility.objects.get(pk=facility_id).name
+    else:
+        facility_name = request.user.facility.name
+
     locale = get_language_from_request(request)
     translation.activate(locale)
     filepath = os.path.join(conf.KOLIBRI_HOME, "temp", filename)
@@ -48,8 +54,11 @@ def download_csv_file(request, filename):
         ).replace("-", "_")
         + ".csv"
     )
+
+    # Append the facility name to the beginning of the filename
+    filename_with_facility = "{}_{}".format(facility_name, str(exported_filename))
     response["Content-Disposition"] = "attachment; filename={}".format(
-        str(exported_filename)
+        filename_with_facility
     )
 
     # set the content-length to the file size


Test patch: