Skip to content

Commit

Permalink
feat: create get_course_videos_qset API call
Browse files Browse the repository at this point in the history
This new call returns a CourseVideo queryset that will allow callers to
efficiently get what they want, instead of having to bring back a large
serialized object that may have many fields that they don't care about.
  • Loading branch information
ormsbee committed Jan 21, 2025
1 parent 51767be commit 4acdf52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,18 @@ def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc
)


def get_course_videos_qset(course_id):
"""
Get a QuerySet of CourseVideos for a given course.
This assumes that the caller can further filter as necessary.
"""
return CourseVideo.objects.select_related('video').filter(
course_id=str(course_id),
is_hidden=False,
)


def get_transcript_details_for_course(course_id):
"""
Get all the transcripts for a course and return details.
Expand Down
7 changes: 7 additions & 0 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,13 @@ def test_get_video_ids_for_course_no_course_videos(self):

self.assertEqual(len(course_transcript), 0)

def test_get_course_videos_qset(self):
"""Test getting a minimal queryset."""
with self.assertNumQueries(1):
course_videos_qset = api.get_course_videos_qset(self.course_id)
course_video = course_videos_qset.get(video__edx_video_id="super-soaker")
self.assertEqual(course_video.video.client_video_id, "Shallow Swordfish")


@ddt
class GetYouTubeProfileVideosTest(TestCase):
Expand Down

0 comments on commit 4acdf52

Please sign in to comment.