Unverified Commit ad63a296 by M. Rehan Committed by GitHub

Merge pull request #141 from edx/mrehan/fix-external-vid-imports

Fix existing external videos import into a course
parents 74cd7fc3 08affff0
...@@ -57,6 +57,7 @@ class VideoImageAdmin(admin.ModelAdmin): ...@@ -57,6 +57,7 @@ class VideoImageAdmin(admin.ModelAdmin):
class CourseVideoAdmin(admin.ModelAdmin): class CourseVideoAdmin(admin.ModelAdmin):
list_display = ('course_id', 'get_video_id', 'is_hidden') list_display = ('course_id', 'get_video_id', 'is_hidden')
search_fields = ('id', 'course_id', 'video__status', 'video__edx_video_id')
def get_video_id(self, obj): def get_video_id(self, obj):
return obj.video.edx_video_id return obj.video.edx_video_id
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
""" """
The internal API for VAL. The internal API for VAL.
""" """
import os
import logging import logging
from enum import Enum from enum import Enum
from uuid import uuid4 from uuid import uuid4
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files import File
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from fs import open_fs from fs import open_fs
from fs.errors import ResourceNotFound from fs.errors import ResourceNotFound
...@@ -36,6 +34,7 @@ from edxval.models import ( ...@@ -36,6 +34,7 @@ from edxval.models import (
Video, Video,
VideoImage, VideoImage,
VideoTranscript, VideoTranscript,
EXTERNAL_VIDEO_STATUS,
ThirdPartyTranscriptCredentialsState, ThirdPartyTranscriptCredentialsState,
) )
from edxval.serializers import TranscriptPreferenceSerializer, TranscriptSerializer, VideoSerializer from edxval.serializers import TranscriptPreferenceSerializer, TranscriptSerializer, VideoSerializer
...@@ -122,7 +121,7 @@ def create_external_video(display_name): ...@@ -122,7 +121,7 @@ def create_external_video(display_name):
""" """
return create_video({ return create_video({
'edx_video_id': generate_video_id(), 'edx_video_id': generate_video_id(),
'status': 'external', 'status': EXTERNAL_VIDEO_STATUS,
'client_video_id': display_name, 'client_video_id': display_name,
'duration': 0, 'duration': 0,
'encoded_videos': [], 'encoded_videos': [],
...@@ -982,7 +981,11 @@ def import_from_xml(xml, edx_video_id, resource_fs, static_dir, external_transcr ...@@ -982,7 +981,11 @@ def import_from_xml(xml, edx_video_id, resource_fs, static_dir, external_transcr
edx_video_id, edx_video_id,
course_id, course_id,
) )
if course_id:
# We don't want to link an existing video to course if its an external video.
# External videos do not have any playback profiles associated, these are just to track video
# transcripts for those video components who do not use edx hosted videos for playback.
if course_id and video.status != EXTERNAL_VIDEO_STATUS:
course_video, __ = CourseVideo.get_or_create_with_validation(video=video, course_id=course_id) course_video, __ = CourseVideo.get_or_create_with_validation(video=video, course_id=course_id)
image_file_name = xml.get('image', '').strip() image_file_name = xml.get('image', '').strip()
......
...@@ -33,6 +33,7 @@ logger = logging.getLogger(__name__) # pylint: disable=C0103 ...@@ -33,6 +33,7 @@ logger = logging.getLogger(__name__) # pylint: disable=C0103
URL_REGEX = r'^[a-zA-Z0-9\-_]*$' URL_REGEX = r'^[a-zA-Z0-9\-_]*$'
LIST_MAX_ITEMS = 3 LIST_MAX_ITEMS = 3
EXTERNAL_VIDEO_STATUS = 'external'
class ModelFactoryWithValidation(object): class ModelFactoryWithValidation(object):
......
...@@ -7,7 +7,8 @@ from edxval.models import ( ...@@ -7,7 +7,8 @@ from edxval.models import (
TranscriptProviderType, TranscriptProviderType,
Cielo24Fidelity, Cielo24Fidelity,
Cielo24Turnaround, Cielo24Turnaround,
ThreePlayTurnaround ThreePlayTurnaround,
EXTERNAL_VIDEO_STATUS
) )
from edxval.utils import TranscriptFormat from edxval.utils import TranscriptFormat
...@@ -136,6 +137,12 @@ VIDEO_DICT_DIFFERENT_ID_FISH = dict( ...@@ -136,6 +137,12 @@ VIDEO_DICT_DIFFERENT_ID_FISH = dict(
edx_video_id="medium-soaker", edx_video_id="medium-soaker",
status="test", status="test",
) )
EXTERNAL_VIDEO_DICT_FISH = dict(
client_video_id="External Video",
duration=0.0,
edx_video_id="external-video",
status=EXTERNAL_VIDEO_STATUS,
)
ENCODED_VIDEO_DICT_FISH_MOBILE = dict( ENCODED_VIDEO_DICT_FISH_MOBILE = dict(
url="https://www.swordsingers.com", url="https://www.swordsingers.com",
file_size=9000, file_size=9000,
......
...@@ -1431,6 +1431,26 @@ class ImportTest(TestCase): ...@@ -1431,6 +1431,26 @@ class ImportTest(TestCase):
xml = self.make_import_xml(video_dict=constants.VIDEO_DICT_FISH) xml = self.make_import_xml(video_dict=constants.VIDEO_DICT_FISH)
self.assert_invalid_import(xml, "x" * 300) self.assert_invalid_import(xml, "x" * 300)
def test_external_video_not_imported(self):
"""
Verify that external videos are not imported into a course.
"""
# Setup an external Video.
Video.objects.create(**constants.EXTERNAL_VIDEO_DICT_FISH)
xml = self.make_import_xml(video_dict=constants.EXTERNAL_VIDEO_DICT_FISH)
api.import_from_xml(
xml,
constants.EXTERNAL_VIDEO_DICT_FISH['edx_video_id'],
self.file_system,
constants.EXPORT_IMPORT_STATIC_DIR,
course_id='test_course_id'
)
# Assert that the existing video is not imported into the course.
self.assertFalse(CourseVideo.objects.filter(
course_id='test_course_id',
video__edx_video_id=constants.EXTERNAL_VIDEO_DICT_FISH['edx_video_id']
).exists())
def test_external_no_video_transcript(self): def test_external_no_video_transcript(self):
""" """
Verify that transcript import for external video working as expected when there is no transcript. Verify that transcript import for external video working as expected when there is no transcript.
......
...@@ -41,7 +41,7 @@ def load_requirements(*requirements_paths): ...@@ -41,7 +41,7 @@ def load_requirements(*requirements_paths):
setup( setup(
name='edxval', name='edxval',
version='0.1.16', version='0.1.17',
author='edX', author='edX',
url='http://github.com/edx/edx-val', url='http://github.com/edx/edx-val',
description='edx-val', description='edx-val',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment