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

Get spanish translations from active subjects #4445

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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',
Copy link
Contributor

Choose a reason for hiding this comment

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

This argument should be lookup, I don't think active subjects (a property) would work here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it locally, and it appears to be working fine.

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
Loading