Skip to content

Commit

Permalink
chore: get spanish translations from active subjects (#4445)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-56 authored Sep 18, 2024
1 parent c99bc3a commit 599858f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_products(self, product_type, product_source):
).filter(Q(num_orgs__gt=0) & Q(card_image__isnull=False) & ~Q(card_image=''))

subject_translations = Prefetch(
'courses__subjects__translations',
'active_subjects__translations',
queryset=SubjectTranslation.objects.filter(language_code='es'),
to_attr='spanish_translations'
)
Expand Down Expand Up @@ -167,7 +167,7 @@ def get_transformed_data(self, product, product_type):
data.update({
"Subjects": ", ".join(subject.name for subject in product.active_subjects),
"Subjects Spanish": ", ".join(
translation.name for subject in product.subjects
translation.name for subject in product.active_subjects
for translation in subject.spanish_translations
),
"Languages": ", ".join(language.code for language in product.active_languages),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import factory
import mock
from django.core.management import CommandError, call_command
from django.db.models import Prefetch, prefetch_related_objects
from django.test import TestCase

from course_discovery.apps.course_metadata.choices import CourseRunStatus, ProgramStatus
from course_discovery.apps.course_metadata.management.commands.populate_product_catalog import Command
from course_discovery.apps.course_metadata.models import Course, CourseType, ProgramType
from course_discovery.apps.course_metadata.models import Course, CourseType, ProgramType, SubjectTranslation
from course_discovery.apps.course_metadata.tests.factories import (
CourseFactory, CourseRunFactory, CourseTypeFactory, DegreeFactory, OrganizationFactory, PartnerFactory,
ProgramTypeFactory, SeatFactory, SourceFactory, SubjectFactory
Expand Down Expand Up @@ -406,6 +407,13 @@ def test_get_transformed_data_for_degree(self):
product = self.degrees[0]
command = Command()
product_authoring_orgs = product.authoring_organizations.all()
subject_translations = Prefetch(
"active_subjects__translations",
queryset=SubjectTranslation.objects.filter(language_code="es"),
to_attr="spanish_translations",
)
prefetch_related_objects([product], subject_translations)

transformed_prod_data = command.get_transformed_data(product, "degree")
assert transformed_prod_data == {
"UUID": str(product.uuid.hex),
Expand All @@ -418,7 +426,7 @@ def test_get_transformed_data_for_degree(self):
"Languages": ", ".join(language.code for language in product.active_languages),
"Subjects": ", ".join(subject.name for subject in product.active_subjects),
"Subjects Spanish": ", ".join(
translation.name for subject in product.subjects
translation.name for subject in product.active_subjects
for translation in subject.spanish_translations
),
"Marketing URL": product.marketing_url,
Expand Down

0 comments on commit 599858f

Please sign in to comment.