Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly map language labels #4018

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions contentcuration/kolibri_public/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ def _get_available_languages(base_queryset):
# Updated to use contentcuration Language model
from contentcuration.models import Language

langs = Language.objects.filter(
id__in=base_queryset.exclude(lang=None)
.values_list("lang_id", flat=True)
.distinct()
).values("id", "lang_name")
langs = map(
# Updated to use contentcuration field names
# Convert language objects to dicts mapped to the kolibri field names
lambda x: {"id": x["id"], "lang_name": x["native_name"]},
Language.objects.filter(
id__in=base_queryset.exclude(lang=None)
.values_list("lang_id", flat=True)
.distinct()
).values("id", "native_name")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can do something like lang_name="native_name" but this works

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, will update!

)
return list(langs)


Expand Down
9 changes: 9 additions & 0 deletions contentcuration/kolibri_public/tests/test_content_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rest_framework.test import APITestCase

from contentcuration.models import generate_storage_url
from contentcuration.models import Language


kind_activity_map = {
Expand Down Expand Up @@ -186,6 +187,14 @@ def test_contentnode_list(self):
self.assertEqual(len(response.data), expected_output)
self._assert_nodes(response.data, nodes)

def test_contentnode_list_labels(self):
nodes = self.root.get_descendants(include_self=True).filter(available=True)
response = self._get(reverse("publiccontentnode-list"), data={"max_results": 1})
node_languages = Language.objects.filter(contentnode__in=nodes)
self.assertEqual(len(response.data["labels"]["languages"]), node_languages.distinct().count())
for lang in response.data["labels"]["languages"]:
self.assertTrue(node_languages.filter(native_name=lang["lang_name"]).exists())

def test_contentnode_list_headers(self):
channel = models.ChannelMetadata.objects.get()
channel.last_updated = datetime.datetime.now()
Expand Down