From 0c132e62dbd976c3b84b67252c60a877d3cce6d6 Mon Sep 17 00:00:00 2001 From: Muhammad Afaq Shuaib Date: Tue, 10 Sep 2024 17:27:34 +0500 Subject: [PATCH] chore: rename a variable --- .../commands/populate_product_catalog.py | 7 ++++--- .../tests/test_populate_product_catalog.py | 4 ++-- course_discovery/apps/course_metadata/models.py | 14 ++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py index 6b6f3b7530..aa51d80035 100644 --- a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py +++ b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py @@ -105,7 +105,8 @@ def get_products(self, product_type, product_source): subject_translations ) elif product_type == 'degree': - queryset = Program.objects.marketable().exclude(degree__isnull=True).select_related('partner', 'type') + queryset = Program.objects.marketable().exclude(degree__isnull=True) \ + .select_related('partner', 'type', 'primary_subject_override', 'language_override') if product_source: queryset = queryset.filter(product_source__slug=product_source) @@ -164,12 +165,12 @@ def get_transformed_data(self, product, product_type): }) elif product_type == 'degree': data.update({ - "Subjects": ", ".join(subject.name for subject in product.subjects), + "Subjects": ", ".join(subject.name for subject in product.active_subjects), "Subjects Spanish": ", ".join( translation.name for subject in product.subjects for translation in subject.spanish_translations ), - "Languages": ", ".join(language.code for language in product.languages), + "Languages": ", ".join(language.code for language in product.active_languages), "Marketing Image": product.card_image.url if product.card_image else "", }) diff --git a/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py b/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py index 557cfb1dbf..511034edc3 100644 --- a/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py +++ b/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py @@ -309,8 +309,8 @@ def test_get_transformed_data_for_degree(self): org.logo_image.url for org in product_authoring_orgs if org.logo_image ), "Organizations Abbr": ", ".join(org.key for org in product_authoring_orgs), - "Languages": ", ".join(language.code for language in product.languages), - "Subjects": ", ".join(subject.name for subject in product.subjects), + "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 for translation in subject.spanish_translations diff --git a/course_discovery/apps/course_metadata/models.py b/course_discovery/apps/course_metadata/models.py index 93f221c868..26d81bc6a4 100644 --- a/course_discovery/apps/course_metadata/models.py +++ b/course_discovery/apps/course_metadata/models.py @@ -3526,7 +3526,7 @@ def active_languages(self): """ if self.language_override: return {self.language_override} - return {course_run.language for course_run in self.course_runs if course_run.language is not None} + return self.languages @property def transcript_languages(self): @@ -3558,13 +3558,15 @@ def active_subjects(self): Note: This method gives preference to the primary_subject_override over the primary subject of the courses. """ + subjects = self.subjects + if self.primary_subject_override: - if self.primary_subject_override not in self.subjects.all(): - product_subjects = [self.primary_subject_override] + list(self.subjects.all()) - else: - product_subjects = list(self.subjects.all()) + if self.primary_subject_override not in subjects: + subjects = [self.primary_subject_override] + subjects + else: + subjects = [self.primary_subject_override] + [subject for subject in subjects if subject != self.primary_subject_override] - return product_subjects + return subjects @property def topics(self):