Skip to content

Commit

Permalink
feat: add util method in edx-val for listing transcript_languages for…
Browse files Browse the repository at this point in the history
… a course
  • Loading branch information
AfaqShuaib09 committed Feb 18, 2025
1 parent b7c5db6 commit af472a7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion edxval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
init
"""

__version__ = '2.9.0'
__version__ = '2.9.1'
24 changes: 22 additions & 2 deletions edxval/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""
The internal API for VAL.
"""


import logging
from enum import Enum
from uuid import uuid4

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.base import ContentFile
from django.core.paginator import Paginator
Expand All @@ -18,6 +17,7 @@
from lxml.etree import Element, SubElement
from pysrt.srtexc import Error

import cachetools.func
from edxval.config.waffle import OVERRIDE_EXISTING_IMPORTED_TRANSCRIPTS
from edxval.exceptions import (
InvalidTranscriptFormat,
Expand Down Expand Up @@ -733,6 +733,26 @@ def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc
)


@cachetools.func.ttl_cache(maxsize=None, ttl=settings.TRANSCRIPT_LANG_CACHE_TIMEOUT)
def get_transcript_languages(course_id, provider_type):
"""
Returns a list of languages for which transcripts are available for a course
Args:
course_id (str): course id
provider_type (str): transcript provider type
Returns:
(list): A list of language codes
"""
course_video_ids = CourseVideo.objects.filter(course_id=course_id, is_hidden=False).values_list('video__id')
transcript_languages = (
VideoTranscript.objects.filter(video__id__in=course_video_ids, provider=provider_type)
.values_list("language_code", flat=True).distinct()
)
return list(transcript_languages)


def get_course_videos_qset(course_id):
"""
Get a QuerySet of CourseVideos for a given course.
Expand Down
2 changes: 2 additions & 0 deletions edxval/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,5 @@
}
},
]

TRANSCRIPT_LANG_CACHE_TIMEOUT = 60 * 60 * 24 # 24 hours
12 changes: 12 additions & 0 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3189,6 +3189,18 @@ def test_get_transcript_details_for_course_no_course_videos(self):

self.assertEqual(len(course_transcript), 0)

@data(
(TranscriptProviderType.THREE_PLAY_MEDIA, ['en']),
(TranscriptProviderType.CIELO24, ['fr'])
)
@unpack
def test_get_transcript_languages_for_course(self, provider_type, expected_languages):
"""
Verify that `get_transcript_languages` api function works as expected.
"""
transcript_languages = api.get_transcript_languages(self.course_id1, provider_type)
self.assertEqual(transcript_languages, expected_languages)


@ddt
class TranscriptPreferencesTest(TestCase):
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pillow # for reserved keywords linter
edx-toggles>=2.0.0
lxml
pysrt
cachetools

0 comments on commit af472a7

Please sign in to comment.