-
Notifications
You must be signed in to change notification settings - Fork 31
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
add: util method in edx-val for listing transcript_languages for a course #565
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
init | ||
""" | ||
|
||
__version__ = '2.9.0' | ||
__version__ = '2.9.1' |
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 | ||
|
@@ -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, | ||
|
@@ -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): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method returns a language even if only one of the available course videos has a transcript in that language. Is this expected behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, it's expected. Output will be union of all transcript_languages with 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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,3 +193,5 @@ | |
} | ||
}, | ||
] | ||
|
||
TRANSCRIPT_LANG_CACHE_TIMEOUT = 60 * 60 * 24 # 24 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this import should be in 2nd level as this is a 3rd party package. Not sure why quality did not fail on this. You can try isort to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already used isort on this file