Commit ff30ac02 by muhammad-ammar

support video images for course re-run and import/export

parent 4894d064
...@@ -10,5 +10,6 @@ script: ...@@ -10,5 +10,6 @@ script:
branches: branches:
only: only:
- master - master
- ammar/course-rerun-import-export
after_success: after_success:
coveralls coveralls
...@@ -61,6 +61,7 @@ def create_video(video_data): ...@@ -61,6 +61,7 @@ def create_video(video_data):
file_size: size of the video in bytes file_size: size of the video in bytes
profile: ID of the profile profile: ID of the profile
courses: Courses associated with this video courses: Courses associated with this video
image: poster image file name for a particular course
} }
Raises: Raises:
...@@ -476,21 +477,32 @@ def copy_course_videos(source_course_id, destination_course_id): ...@@ -476,21 +477,32 @@ def copy_course_videos(source_course_id, destination_course_id):
if source_course_id == destination_course_id: if source_course_id == destination_course_id:
return return
videos = Video.objects.filter(courses__course_id=unicode(source_course_id)) course_videos = CourseVideo.objects.select_related('video', 'video_image').filter(
course_id=unicode(source_course_id)
)
for video in videos: for course_video in course_videos:
CourseVideo.objects.get_or_create( dest_course_video, __ = CourseVideo.objects.get_or_create(
video=video, video=course_video.video,
course_id=destination_course_id course_id=destination_course_id
) )
try:
VideoImage.create_or_update(
course_video=dest_course_video,
image_data=None,
file_name=course_video.video_image.image.name
)
except VideoImage.DoesNotExist:
pass
def export_to_xml(edx_video_id): def export_to_xml(edx_video_id, course_id=None):
""" """
Exports data about the given edx_video_id into the given xml object. Exports data about the given edx_video_id into the given xml object.
Args: Args:
edx_video_id (str): The ID of the video to export edx_video_id (str): The ID of the video to export
course_id (str): The ID of the course with which this video is associated
Returns: Returns:
An lxml video_asset element containing export data An lxml video_asset element containing export data
...@@ -498,12 +510,21 @@ def export_to_xml(edx_video_id): ...@@ -498,12 +510,21 @@ def export_to_xml(edx_video_id):
Raises: Raises:
ValVideoNotFoundError: if the video does not exist ValVideoNotFoundError: if the video does not exist
""" """
image = ''
video = _get_video(edx_video_id) video = _get_video(edx_video_id)
try:
course_video = CourseVideo.objects.select_related('video_image').get(course_id=course_id, video=video)
image = course_video.video_image.image.name
except ObjectDoesNotExist:
pass
video_el = Element( video_el = Element(
'video_asset', 'video_asset',
attrib={ attrib={
'client_video_id': video.client_video_id, 'client_video_id': video.client_video_id,
'duration': unicode(video.duration), 'duration': unicode(video.duration),
'image': image
} }
) )
for encoded_video in video.encoded_videos.all(): for encoded_video in video.encoded_videos.all():
...@@ -548,7 +569,11 @@ def import_from_xml(xml, edx_video_id, course_id=None): ...@@ -548,7 +569,11 @@ def import_from_xml(xml, edx_video_id, course_id=None):
course_id, course_id,
) )
if course_id: if course_id:
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()
if image_file_name:
VideoImage.create_or_update(course_video, None, image_file_name)
return return
except ValidationError as err: except ValidationError as err:
logger.exception(err.message) logger.exception(err.message)
...@@ -561,6 +586,7 @@ def import_from_xml(xml, edx_video_id, course_id=None): ...@@ -561,6 +586,7 @@ def import_from_xml(xml, edx_video_id, course_id=None):
'edx_video_id': edx_video_id, 'edx_video_id': edx_video_id,
'client_video_id': xml.get('client_video_id'), 'client_video_id': xml.get('client_video_id'),
'duration': xml.get('duration'), 'duration': xml.get('duration'),
'image': xml.get('image'),
'status': 'imported', 'status': 'imported',
'encoded_videos': [], 'encoded_videos': [],
'courses': [course_id] if course_id else [], 'courses': [course_id] if course_id else [],
......
...@@ -164,6 +164,7 @@ class VideoSerializer(serializers.ModelSerializer): ...@@ -164,6 +164,7 @@ class VideoSerializer(serializers.ModelSerializer):
Create the video and its nested resources. Create the video and its nested resources.
""" """
courses = validated_data.pop("courses", []) courses = validated_data.pop("courses", [])
image = validated_data.pop("image", None)
encoded_videos = validated_data.pop("encoded_videos", []) encoded_videos = validated_data.pop("encoded_videos", [])
subtitles = validated_data.pop("subtitles", []) subtitles = validated_data.pop("subtitles", [])
...@@ -213,6 +214,7 @@ class VideoSerializer(serializers.ModelSerializer): ...@@ -213,6 +214,7 @@ class VideoSerializer(serializers.ModelSerializer):
for subtitle_data in validated_data.get("subtitles", []) for subtitle_data in validated_data.get("subtitles", [])
) )
image = validated_data.get("image")
# Set courses # Set courses
# NOTE: for backwards compatibility with the DRF v2 behavior, # NOTE: for backwards compatibility with the DRF v2 behavior,
# we do NOT delete existing course videos during the update. # we do NOT delete existing course videos during the update.
......
...@@ -39,7 +39,7 @@ def load_requirements(*requirements_paths): ...@@ -39,7 +39,7 @@ def load_requirements(*requirements_paths):
setup( setup(
name='edxval', name='edxval',
version='0.0.13', version='0.0.14',
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