Skip to content

Commit

Permalink
feat: added transcript_languages_search_facet_names to CourseRunSeria…
Browse files Browse the repository at this point in the history
…lizer (#4302)

Co-authored-by: Maham Akif <[email protected]>
  • Loading branch information
mahamakifdar19 and Maham Akif authored Mar 27, 2024
1 parent 6f90af2 commit a5b1e7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ class CourseRunSerializer(MinimalCourseRunSerializer):
required=False, many=True, slug_field='code',
queryset=LanguageTag.objects.prefetch_related('translations').order_by('name')
)
transcript_languages_search_facet_names = serializers.SerializerMethodField()
video = VideoSerializer(required=False, allow_null=True, source='get_video')
instructors = serializers.SerializerMethodField(help_text='This field is deprecated. Use staff.')
staff = SlugRelatedFieldWithReadSerializer(slug_field='uuid', required=False, many=True,
Expand Down Expand Up @@ -1066,7 +1067,8 @@ class Meta(MinimalCourseRunSerializer.Meta):
'level_type', 'mobile_available', 'hidden', 'reporting_type', 'eligible_for_financial_aid',
'first_enrollable_paid_seat_price', 'has_ofac_restrictions', 'ofac_comment',
'enrollment_count', 'recent_enrollment_count', 'expected_program_type', 'expected_program_name',
'course_uuid', 'estimated_hours', 'content_language_search_facet_name', 'enterprise_subscription_inclusion'
'course_uuid', 'estimated_hours', 'content_language_search_facet_name', 'enterprise_subscription_inclusion',
'transcript_languages_search_facet_names'
)
read_only_fields = ('enrollment_count', 'recent_enrollment_count', 'content_language_search_facet_name',
'enterprise_subscription_inclusion')
Expand All @@ -1084,6 +1086,9 @@ def get_content_language_search_facet_name(self, obj):
return None
return language.get_search_facet_display(translate=True)

def get_transcript_languages_search_facet_names(self, obj):
return [lang.get_search_facet_display() for lang in obj.transcript_languages.all()]

def update_video(self, instance, video_data):
# A separate video object is a historical concept. These days, we really just use the link address. So
# we look up a foreign key just based on the link and don't bother trying to match or set any other fields.
Expand Down
8 changes: 7 additions & 1 deletion course_discovery/apps/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def get_expected_data(cls, course_run, request):
'hidden': course_run.hidden,
'content_language': course_run.language.code,
'content_language_search_facet_name': course_run.language.get_search_facet_display(translate=True),
'transcript_languages': [],
'transcript_languages': [lang.code for lang in course_run.transcript_languages.all()],
'min_effort': course_run.min_effort,
'max_effort': course_run.max_effort,
'weeks_to_complete': course_run.weeks_to_complete,
Expand All @@ -705,12 +705,18 @@ def get_expected_data(cls, course_run, request):
'ofac_comment': course_run.ofac_comment,
'estimated_hours': get_course_run_estimated_hours(course_run),
'enterprise_subscription_inclusion': course_run.enterprise_subscription_inclusion,
'transcript_languages_search_facet_names': [
lang.get_search_facet_display() for lang in course_run.transcript_languages.all()
]
})
return expected

def test_data(self):
request = make_request()
course_run = CourseRunFactory()
# Adjusting transcript_languages here for CourseRunSerializerTests to avoid affecting
# other tests that use CourseRunFactory
course_run.transcript_languages.set([LanguageTag.objects.first()])
serializer = self.serializer_class(course_run, context={'request': request})
expected = self.get_expected_data(course_run, request)

Expand Down
2 changes: 1 addition & 1 deletion course_discovery/apps/ietf_language_tags/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_search_facet_display(self, translate=False):
# All other languages are grouped by macrolanguage.
if self.code.startswith('zh'):
return self.name_t if translate else self.name
return self.translated_macrolanguage if translate else self.macrolanguage
return self.translated_macrolanguage if translate and self.name_t else self.macrolanguage


class LanguageTagTranslation(TranslatedFieldsModel):
Expand Down

0 comments on commit a5b1e7e

Please sign in to comment.