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 20, 2025
1 parent b7c5db6 commit 0855bc0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 29 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
4 changes: 2 additions & 2 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ charset-normalizer==3.4.1
# via requests
colorama==0.4.6
# via tox
coverage[toml]==7.6.10
coverage[toml]==7.6.12
# via coveralls
coveralls==4.0.1
# via -r requirements/ci.in
Expand Down Expand Up @@ -48,5 +48,5 @@ urllib3==2.2.3
# via
# -c requirements/common_constraints.txt
# requests
virtualenv==20.29.1
virtualenv==20.29.2
# via tox
18 changes: 9 additions & 9 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ code-annotations==2.2.0
# edx-toggles
colorama==0.4.6
# via tox
coverage[toml]==7.6.10
coverage[toml]==7.6.12
# via
# -r requirements/test.in
# coveralls
# pytest-cov
coveralls==4.0.1
# via -r requirements/ci.in
cryptography==44.0.0
cryptography==44.0.1
# via
# pyjwt
# secretstorage
Expand All @@ -69,7 +69,7 @@ dill==0.3.9
# via pylint
distlib==0.3.9
# via virtualenv
django==4.2.18
django==4.2.19
# via
# -c requirements/common_constraints.txt
# -r requirements/base.in
Expand Down Expand Up @@ -165,7 +165,7 @@ jinja2==3.1.5
# diff-cover
keyring==25.6.0
# via twine
lxml==5.3.0
lxml==5.3.1
# via -r requirements/base.in
markdown-it-py==3.0.0
# via rich
Expand All @@ -183,7 +183,7 @@ more-itertools==10.6.0
# jaraco-functools
multidict==6.1.0
# via yarl
newrelic==10.5.0
newrelic==10.6.0
# via edx-django-utils
nh3==0.2.20
# via readme-renderer
Expand All @@ -195,7 +195,7 @@ packaging==24.2
# twine
pact-python==2.3.1
# via -r requirements/test.in
pbr==6.1.0
pbr==6.1.1
# via stevedore
pillow==11.1.0
# via -r requirements/base.in
Expand Down Expand Up @@ -248,7 +248,7 @@ pylint-plugin-utils==0.8.2
# via
# pylint-celery
# pylint-django
pymongo==4.11
pymongo==4.11.1
# via edx-opaque-keys
pynacl==1.5.0
# via edx-django-utils
Expand All @@ -262,7 +262,7 @@ pytest==8.3.4
# pytest-django
pytest-cov==6.0.0
# via -r requirements/test.in
pytest-django==4.9.0
pytest-django==4.10.0
# via -r requirements/test.in
python-slugify==8.0.4
# via code-annotations
Expand Down Expand Up @@ -336,7 +336,7 @@ urllib3==2.2.3
# twine
uvicorn==0.34.0
# via pact-python
virtualenv==20.29.1
virtualenv==20.29.2
# via tox
yarl==1.18.3
# via pact-python
Expand Down
16 changes: 8 additions & 8 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ code-annotations==2.2.0
# via
# edx-lint
# edx-toggles
coverage[toml]==7.6.10
coverage[toml]==7.6.12
# via
# -r requirements/test.in
# pytest-cov
cryptography==44.0.0
cryptography==44.0.1
# via
# pyjwt
# secretstorage
ddt==1.7.2
# via -r requirements/test.in
dill==0.3.9
# via pylint
django==4.2.18
django==4.2.19
# via
# -c requirements/common_constraints.txt
# -r requirements/base.in
Expand Down Expand Up @@ -143,7 +143,7 @@ jinja2==3.1.5
# via code-annotations
keyring==25.6.0
# via twine
lxml==5.3.0
lxml==5.3.1
# via -r requirements/base.in
markdown-it-py==3.0.0
# via rich
Expand All @@ -161,7 +161,7 @@ more-itertools==10.6.0
# jaraco-functools
multidict==6.1.0
# via yarl
newrelic==10.5.0
newrelic==10.6.0
# via edx-django-utils
nh3==0.2.20
# via readme-renderer
Expand All @@ -171,7 +171,7 @@ packaging==24.2
# twine
pact-python==2.3.1
# via -r requirements/test.in
pbr==6.1.0
pbr==6.1.1
# via stevedore
pillow==11.1.0
# via -r requirements/base.in
Expand Down Expand Up @@ -217,7 +217,7 @@ pylint-plugin-utils==0.8.2
# via
# pylint-celery
# pylint-django
pymongo==4.11
pymongo==4.11.1
# via edx-opaque-keys
pynacl==1.5.0
# via edx-django-utils
Expand All @@ -229,7 +229,7 @@ pytest==8.3.4
# pytest-django
pytest-cov==6.0.0
# via -r requirements/test.in
pytest-django==4.9.0
pytest-django==4.10.0
# via -r requirements/test.in
python-slugify==8.0.4
# via code-annotations
Expand Down
14 changes: 7 additions & 7 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ click==8.1.8
# uvicorn
code-annotations==2.2.0
# via edx-toggles
coverage[toml]==7.6.10
coverage[toml]==7.6.12
# via
# -r requirements/test.in
# pytest-cov
cryptography==44.0.0
cryptography==44.0.1
# via pyjwt
ddt==1.7.2
# via -r requirements/test.in
Expand Down Expand Up @@ -100,21 +100,21 @@ iniconfig==2.0.0
# via pytest
jinja2==3.1.5
# via code-annotations
lxml==5.3.0
lxml==5.3.1
# via -r requirements/base.in
markupsafe==3.0.2
# via jinja2
mock==5.1.0
# via -r requirements/test.in
multidict==6.1.0
# via yarl
newrelic==10.5.0
newrelic==10.6.0
# via edx-django-utils
packaging==24.2
# via pytest
pact-python==2.3.1
# via -r requirements/test.in
pbr==6.1.0
pbr==6.1.1
# via stevedore
pillow==11.1.0
# via -r requirements/base.in
Expand All @@ -136,7 +136,7 @@ pyjwt[crypto]==2.10.1
# via
# drf-jwt
# edx-drf-extensions
pymongo==4.11
pymongo==4.11.1
# via edx-opaque-keys
pynacl==1.5.0
# via edx-django-utils
Expand All @@ -148,7 +148,7 @@ pytest==8.3.4
# pytest-django
pytest-cov==6.0.0
# via -r requirements/test.in
pytest-django==4.9.0
pytest-django==4.10.0
# via -r requirements/test.in
python-slugify==8.0.4
# via code-annotations
Expand Down

0 comments on commit 0855bc0

Please sign in to comment.