Commit 7c491711 by Mushtaq Ali

save video image in image model

parent 32c453da
......@@ -3,7 +3,7 @@ Admin file for django app edxval.
"""
from django.contrib import admin
from .models import Video, Profile, EncodedVideo, Subtitle, CourseVideo
from .models import Video, Profile, EncodedVideo, Subtitle, CourseVideo, VideoImage
class ProfileAdmin(admin.ModelAdmin): # pylint: disable=C0111
......@@ -30,6 +30,12 @@ class VideoAdmin(admin.ModelAdmin): # pylint: disable=C0111
admin_order_field = 'edx_video_id'
inlines = [CourseVideoInline, EncodedVideoInline]
class ImageVideoAdmin(admin.ModelAdmin):
model = VideoImage
verbose_name = "Video Image"
verbose_name_plural = "Video Images"
admin.site.register(Profile, ProfileAdmin)
admin.site.register(Video, VideoAdmin)
admin.site.register(Subtitle)
admin.site.register(VideoImage, ImageVideoAdmin)
......@@ -10,10 +10,11 @@ from enum import Enum
from django.core.exceptions import ValidationError
from edxval.models import Video, EncodedVideo, CourseVideo, Profile
from edxval.models import Video, EncodedVideo, CourseVideo, Profile, VideoImage
from edxval.serializers import VideoSerializer
logger = logging.getLogger(__name__) # pylint: disable=C0103
from django.core.files.base import ContentFile
class ValError(Exception):
......@@ -182,13 +183,13 @@ def update_video_status(edx_video_id, status):
video.save()
def update_video_thumbnail(edx_video_id, thumbnail):
def update_video_image(edx_video_id, course_id, serialized_data):
"""
Update video thumbail for an existing video.
Update video image for an existing video.
Args:
edx_video_id: ID of the video
thumbnail: Thumbnail file for video.
serialized_data: Serialized data of image for video.
Raises:
Raises ValVideoNotFoundError if the video cannot be retrieved.
......@@ -197,13 +198,18 @@ def update_video_thumbnail(edx_video_id, thumbnail):
try:
video = _get_video(edx_video_id)
except Video.DoesNotExist:
error_message = u"Video not found when trying to update thumbnail with edx_video_id: {0}".format(
error_message = u"Video not found when trying to update video image with edx_video_id: {0}".format(
edx_video_id
)
raise ValVideoNotFoundError(error_message)
video.thumbnail = thumbnail
video.save()
video_image, _ = VideoImage.objects.get_or_create(
video=video,
course_id=course_id
)
video_image.image.save('', ContentFile(serialized_data))
video_image.save()
def create_profile(profile_name):
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import edxval.models
class Migration(migrations.Migration):
dependencies = [
('edxval', '0004_data__add_hls_profile'),
]
operations = [
migrations.CreateModel(
name='VideoImage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('course_id', models.CharField(max_length=255)),
('image', edxval.models.CustomizableFileField(null=True, blank=True)),
('video', models.ForeignKey(related_name='thumbnails', to='edxval.Video')),
],
),
]
......@@ -13,18 +13,12 @@ invalid profile_name will be returned.
import logging
# from datetime import datetime
from django.conf import settings
from django.db import models
from django.dispatch import receiver
from django.core.validators import MinValueValidator, RegexValidator
from django.core.urlresolvers import reverse
from django.core.files.base import ContentFile
from django.core.files.storage import get_storage_class
from django.db import models, transaction
from django.utils.functional import cached_property
# from openedx.core.storage import get_storage
logger = logging.getLogger(__name__) # pylint: disable=C0103
......@@ -94,11 +88,11 @@ def _directory_name(edx_video_id):
return '{}{}'.format(settings.VIDEO_THUMBNAIL_SETTINGS.get('DIRECTORY_PREFIX', ''), edx_video_id)
def video_thumbnail_path_name(video_model, filename): # pylint:disable=unused-argument
def video_thumbnail_path_name(thumbnail_model, filename): # pylint:disable=unused-argument
"""
Returns path name to use for the given Video instance.
"""
return _create_path(_directory_name(video_model.edx_video_id), filename)
return _create_path(_directory_name(thumbnail_model.video_id), filename)
def get_video_thumbnail_storage():
......@@ -110,7 +104,7 @@ def get_video_thumbnail_storage():
)(**settings.VIDEO_THUMBNAIL_SETTINGS.get('STORAGE_KWARGS', {}))
class CustomizableFileField(models.FileField):
class CustomizableFileField(models.ImageField):
"""
Subclass of FileField that allows custom settings to not
be serialized (hard-coded) in migrations. Otherwise,
......@@ -162,18 +156,6 @@ class Video(models.Model):
client_video_id = models.CharField(max_length=255, db_index=True, blank=True)
duration = models.FloatField(validators=[MinValueValidator(0)])
status = models.CharField(max_length=255, db_index=True)
thumbnail = CustomizableFileField()
# def thumbnail_url(self, name, edx_video_id=None):
# path = video_thumbnail_path_name(name, edx_video_id)
# return self._storage.url(path)
#
# @cached_property
# def _storage(self):
# """
# Return the configured django storage backend.
# """
# return get_video_thumbnail_storage()
def get_absolute_url(self):
"""
......@@ -231,6 +213,15 @@ class EncodedVideo(models.Model):
video = models.ForeignKey(Video, related_name="encoded_videos")
class VideoImage(models.Model):
"""
Image model for course video.
"""
course_id = models.CharField(max_length=255)
video = models.ForeignKey(Video, related_name="thumbnails")
image = CustomizableFileField()
SUBTITLE_FORMATS = (
('srt', 'SubRip'),
('sjson', 'SRT JSON')
......
......@@ -183,6 +183,6 @@ COURSE_ID_PATTERN = COURSE_KEY_PATTERN.replace('course_key_string', 'course_id')
VIDEO_THUMBNAIL_SETTINGS = dict(
# Backend storage
# STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage',
# STORAGE_KWARGS=dict(bucket='mushi-mallow-bucket'),
DIRECTORY_PREFIX='videothumbnail/',
# STORAGE_KWARGS=dict(bucket='video-inage-test-bucket'),
DIRECTORY_PREFIX='videoimage/',
)
......@@ -5,4 +5,5 @@ lxml==3.3.6
-e git+https://github.com/edx/django-oauth2-provider.git@0.2.7-fork-edx-6a#egg=django-oauth2-provider==0.2.7-fork-edx-6
-e git+https://github.com/edx/django-rest-framework-oauth.git@f0b503fda8c254a38f97fef802ded4f5fe367f7a#egg=djangorestframework-oauth
django-storages==1.5.2
boto==2.46.1
\ No newline at end of file
boto==2.46.1
Pillow==4.1.0
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