Skip to content

Commit

Permalink
Merge pull request #9602 from rtibbles/unicode_is_the_future
Browse files Browse the repository at this point in the history
Force unicode literals for Python 2 compatibility of string handling.
  • Loading branch information
rtibbles authored Aug 11, 2022
2 parents 15d5962 + 9d29977 commit 07d5e4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions kolibri/core/auth/csv_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions kolibri/core/auth/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import base64
import collections
import sys
import time
import uuid
from datetime import datetime
from importlib import import_module
Expand Down Expand Up @@ -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"})
)
Expand Down
1 change: 1 addition & 0 deletions kolibri/core/public/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
8 changes: 6 additions & 2 deletions kolibri/core/utils/csv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals

import io
import re
import sys
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 07d5e4f

Please sign in to comment.