diff --git a/kolibri/core/auth/csv_utils.py b/kolibri/core/auth/csv_utils.py index da03d386ed0..89f8e84042e 100644 --- a/kolibri/core/auth/csv_utils.py +++ b/kolibri/core/auth/csv_utils.py @@ -97,9 +97,6 @@ def replace_multiple_classrooms(field, obj): ) -map_output = partial(output_mapper, labels=labels, output_mappings=output_mappings) - - input_fields = ( "full_name", "username", @@ -181,6 +178,14 @@ def csv_file_generator(facility, filepath, overwrite=True, demographic=False): csv_file = open_csv_for_writing(filepath) + mappings = {} + + for key in output_mappings: + if demographic or key not in DEMO_FIELDS: + mappings[key] = output_mappings[key] + + map_output = partial(output_mapper, labels=labels, output_mappings=mappings) + with csv_file as f: writer = csv.DictWriter(f, header_labels) logger.info("Creating csv file {filename}".format(filename=filepath)) diff --git a/kolibri/core/auth/test/test_api.py b/kolibri/core/auth/test/test_api.py index 6066ba34c98..07abc7f0413 100644 --- a/kolibri/core/auth/test/test_api.py +++ b/kolibri/core/auth/test/test_api.py @@ -5,6 +5,7 @@ import base64 import collections import sys +import time import uuid from datetime import datetime from importlib import import_module @@ -1104,6 +1105,7 @@ def test_session_update_last_active(self): format="json", ) expire_date = self.client.session.get_expiry_date() + time.sleep(0.01) self.client.get( reverse("kolibri:core:session-detail", kwargs={"pk": "current"}) ) diff --git a/kolibri/core/public/test/test_api.py b/kolibri/core/public/test/test_api.py index 926f9860433..5ba7542e7d1 100644 --- a/kolibri/core/public/test/test_api.py +++ b/kolibri/core/public/test/test_api.py @@ -771,6 +771,7 @@ def test_update_full_queue_should_queue(self): user_id=self.learner.id, instance_id=self.instance_id, keep_alive=10 ) old_updated = queue.updated + time.sleep(0.01) response = self.client.put( reverse("kolibri:core:syncqueue-detail", kwargs={"pk": queue.id}), data={"user": self.learner.id, "instance": self.instance_id}, diff --git a/kolibri/core/utils/csv.py b/kolibri/core/utils/csv.py index 99a48cceb12..ea962ccd79d 100644 --- a/kolibri/core/utils/csv.py +++ b/kolibri/core/utils/csv.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import io import re import sys @@ -35,12 +37,14 @@ def sanitize(value): return value -def output_mapper(obj, labels=None, output_mappings=None): +def output_mapper(obj, labels=None, output_mappings=None, exclude_fields=None): + if exclude_fields is None: + exclude_fields = set() mapped_obj = {} labels = labels or {} output_mappings = output_mappings or {} for header, label in labels.items(): - if header in output_mappings and header in obj: + if header in output_mappings: mapped_obj[label] = sanitize(output_mappings[header](obj)) elif header in obj: mapped_obj[label] = sanitize(obj[header])