Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-val
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-val
Commits
6a85bc9b
Commit
6a85bc9b
authored
May 16, 2017
by
muhammad-ammar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address feedback
parent
04413bc6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
29 deletions
+53
-29
edxval/admin.py
+2
-2
edxval/api.py
+8
-19
edxval/models.py
+22
-5
edxval/serializers.py
+1
-1
edxval/tests/test_api.py
+15
-1
edxval/utils.py
+5
-1
No files found.
edxval/admin.py
View file @
6a85bc9b
...
@@ -36,8 +36,8 @@ class VideoAdmin(admin.ModelAdmin): # pylint: disable=C0111
...
@@ -36,8 +36,8 @@ class VideoAdmin(admin.ModelAdmin): # pylint: disable=C0111
class
VideoImageAdmin
(
admin
.
ModelAdmin
):
class
VideoImageAdmin
(
admin
.
ModelAdmin
):
model
=
VideoImage
model
=
VideoImage
verbose_name
=
"Video Image"
verbose_name
=
'Video Image'
verbose_name_plural
=
"Video Images"
verbose_name_plural
=
'Video Images'
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
admin
.
site
.
register
(
Profile
,
ProfileAdmin
)
admin
.
site
.
register
(
Video
,
VideoAdmin
)
admin
.
site
.
register
(
Video
,
VideoAdmin
)
...
...
edxval/api.py
View file @
6a85bc9b
...
@@ -13,7 +13,6 @@ from django.core.files.base import ContentFile
...
@@ -13,7 +13,6 @@ from django.core.files.base import ContentFile
from
edxval.models
import
Video
,
EncodedVideo
,
CourseVideo
,
Profile
,
VideoImage
from
edxval.models
import
Video
,
EncodedVideo
,
CourseVideo
,
Profile
,
VideoImage
from
edxval.serializers
import
VideoSerializer
from
edxval.serializers
import
VideoSerializer
from
edxval.utils
import
get_video_image_storage
from
edxval.exceptions
import
(
# pylint: disable=unused-import
from
edxval.exceptions
import
(
# pylint: disable=unused-import
ValError
,
ValError
,
ValInternalError
,
ValInternalError
,
...
@@ -145,25 +144,15 @@ def update_video_status(edx_video_id, status):
...
@@ -145,25 +144,15 @@ def update_video_status(edx_video_id, status):
def
get_course_video_image_url
(
course_id
=
None
,
edx_video_id
=
None
,
video_image
=
None
):
def
get_course_video_image_url
(
course_id
=
None
,
edx_video_id
=
None
,
video_image
=
None
):
"""
"""
Returns course video image url.
Returns course video image url or None if no image found
Arguments:
course_id: ID of course
edx_video_id: ID of the video
video_image: VideoImage instance
Returns:
course video image url or None if no image found
"""
"""
storage
=
get_video_image_storage
()
try
:
try
:
if
video_image
is
None
:
if
video_image
is
None
:
video_image
=
CourseVideo
.
objects
.
get
(
course_id
=
course_id
,
video__edx_video_id
=
edx_video_id
)
.
video_image
video_image
=
CourseVideo
.
objects
.
get
(
course_id
=
course_id
,
video__edx_video_id
=
edx_video_id
)
.
video_image
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
None
return
None
return
storage
.
url
(
video_image
.
image
.
name
)
return
video_image
.
image_url
(
)
def
update_video_image
(
edx_video_id
,
course_id
,
image_data
,
file_name
):
def
update_video_image
(
edx_video_id
,
course_id
,
image_data
,
file_name
):
...
@@ -171,22 +160,22 @@ def update_video_image(edx_video_id, course_id, image_data, file_name):
...
@@ -171,22 +160,22 @@ def update_video_image(edx_video_id, course_id, image_data, file_name):
Update video image for an existing video.
Update video image for an existing video.
Arguments:
Arguments:
edx_video_id: ID of th
e video.
image_data (InMemoryUploadedFile): Image data to be saved for a cours
e video.
course_id: ID of course.
image_data: Image data for video.
Returns:
file_name: File name of the image file.
course video image url
Raises:
Raises:
Raises ValVideoNotFoundError if the CourseVideo cannot be retrieved.
Raises ValVideoNotFoundError if the CourseVideo cannot be retrieved.
"""
"""
try
:
try
:
course_video
=
CourseVideo
.
objects
.
get
(
course_id
=
course_id
,
video__edx_video_id
=
edx_video_id
)
course_video
=
CourseVideo
.
objects
.
get
(
course_id
=
course_id
,
video__edx_video_id
=
edx_video_id
)
except
Video
.
DoesNotExist
:
except
Object
DoesNotExist
:
error_message
=
u'CourseVideo not found for edx_video_id: {0}'
.
format
(
edx_video_id
)
error_message
=
u'CourseVideo not found for edx_video_id: {0}'
.
format
(
edx_video_id
)
raise
ValVideoNotFoundError
(
error_message
)
raise
ValVideoNotFoundError
(
error_message
)
video_image
,
_
=
VideoImage
.
create_or_update
(
course_video
,
file_name
,
image_data
)
video_image
,
_
=
VideoImage
.
create_or_update
(
course_video
,
file_name
,
image_data
)
return
get_course_video_image_url
(
video_image
=
video_image
)
return
video_image
.
image_url
(
)
def
create_profile
(
profile_name
):
def
create_profile
(
profile_name
):
...
...
edxval/models.py
View file @
6a85bc9b
...
@@ -145,6 +145,15 @@ class CourseVideo(models.Model, ModelFactoryWithValidation):
...
@@ -145,6 +145,15 @@ class CourseVideo(models.Model, ModelFactoryWithValidation):
"""
"""
unique_together
=
(
"course_id"
,
"video"
)
unique_together
=
(
"course_id"
,
"video"
)
def
image_url
(
self
):
"""
Return image url for a course video image.
"""
try
:
return
self
.
video_image
.
image_url
()
except
VideoImage
.
DoesNotExist
:
pass
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
course_id
return
self
.
course_id
...
@@ -216,21 +225,29 @@ class VideoImage(TimeStampedModel):
...
@@ -216,21 +225,29 @@ class VideoImage(TimeStampedModel):
if
image_data
:
if
image_data
:
with
closing
(
image_data
)
as
image_file
:
with
closing
(
image_data
)
as
image_file
:
file_name
=
'{uuid}{ext}'
.
format
(
uuid
=
uuid4
()
.
hex
,
ext
=
os
.
path
.
splitext
(
file_name
)[
1
])
file_name
=
'{uuid}{ext}'
.
format
(
uuid
=
uuid4
()
.
hex
,
ext
=
os
.
path
.
splitext
(
file_name
)[
1
])
video_image
.
image
.
save
(
file_name
,
image_file
)
try
:
course_id
=
course_video
.
course_id
edx_video_id
=
course_video
.
video
.
edx_video_id
video_image
.
image
.
save
(
file_name
,
image_file
)
except
Exception
:
# pylint: disable=broad-except
logger
.
exception
(
'VAL: Video Image save failed to storage for course_id [
%
s] and video_id [
%
s]'
,
course_id
,
edx_video_id
)
raise
else
:
else
:
video_image
.
image
.
name
=
file_name
video_image
.
image
.
name
=
file_name
video_image
.
save
()
video_image
.
save
()
return
video_image
,
created
return
video_image
,
created
@classmethod
def
image_url
(
self
):
def
image_url
(
cls
,
course_video
):
"""
"""
Return image url for a course video image.
Return image url for a course video image.
"""
"""
storage
=
get_video_image_storage
()
storage
=
get_video_image_storage
()
if
hasattr
(
course_video
,
'video_image'
):
return
storage
.
url
(
self
.
image
.
name
)
return
storage
.
url
(
course_video
.
video_image
.
image
.
name
)
SUBTITLE_FORMATS
=
(
SUBTITLE_FORMATS
=
(
...
...
edxval/serializers.py
View file @
6a85bc9b
...
@@ -92,7 +92,7 @@ class CourseSerializer(serializers.RelatedField):
...
@@ -92,7 +92,7 @@ class CourseSerializer(serializers.RelatedField):
Returns a serializable representation of a CourseVideo instance.
Returns a serializable representation of a CourseVideo instance.
"""
"""
return
{
return
{
course_video
.
course_id
:
VideoImage
.
image_url
(
course_video
)
course_video
.
course_id
:
course_video
.
image_url
(
)
}
}
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
...
...
edxval/tests/test_api.py
View file @
6a85bc9b
...
@@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse
...
@@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse
from
rest_framework
import
status
from
rest_framework
import
status
from
ddt
import
ddt
,
data
from
ddt
import
ddt
,
data
from
edxval.models
import
Profile
,
Video
,
EncodedVideo
,
CourseVideo
from
edxval.models
import
Profile
,
Video
,
EncodedVideo
,
CourseVideo
,
VideoImage
from
edxval
import
api
as
api
from
edxval
import
api
as
api
from
edxval.api
import
(
from
edxval.api
import
(
SortDirection
,
SortDirection
,
...
@@ -1258,3 +1258,17 @@ class CourseVideoImageTest(TestCase):
...
@@ -1258,3 +1258,17 @@ class CourseVideoImageTest(TestCase):
video_data_generator
=
api
.
get_videos_for_ids
([
self
.
edx_video_id
])
video_data_generator
=
api
.
get_videos_for_ids
([
self
.
edx_video_id
])
video_data
=
list
(
video_data_generator
)[
0
]
video_data
=
list
(
video_data_generator
)[
0
]
self
.
assertEqual
(
video_data
[
'courses'
][
0
][
'test-course'
],
self
.
image_url
)
self
.
assertEqual
(
video_data
[
'courses'
][
0
][
'test-course'
],
self
.
image_url
)
@patch
(
'edxval.models.logger'
)
def
test_create_or_update_logging
(
self
,
mock_logger
):
"""
Tests correct message is logged when save to storge is failed in `create_or_update`
"""
with
self
.
assertRaises
(
Exception
)
as
save_exception
:
# pylint: disable=unused-variable
VideoImage
.
create_or_update
(
self
.
course_video
,
'test.jpg'
,
open
(
self
.
image_path2
))
mock_logger
.
exception
.
assert_called_with
(
'VAL: Video Image save failed to storage for course_id [
%
s] and video_id [
%
s]'
,
self
.
course_video
.
course_id
,
self
.
course_video
.
video
.
edx_video_id
)
edxval/utils.py
View file @
6a85bc9b
...
@@ -9,8 +9,12 @@ from django.core.files.storage import get_storage_class
...
@@ -9,8 +9,12 @@ from django.core.files.storage import get_storage_class
def
video_image_path
(
video_image_instance
,
filename
):
# pylint:disable=unused-argument
def
video_image_path
(
video_image_instance
,
filename
):
# pylint:disable=unused-argument
"""
"""
Returns video image path.
Returns video image path.
Arguments:
video_image_instance (VideoImage): This is passed automatically by models.CustomizableImageField
filename (str): name of image file
"""
"""
return
'{}{}'
.
format
(
settings
.
VIDEO_IMAGE_SETTINGS
.
get
(
'DIRECTORY_PREFIX'
,
''
),
filename
)
return
u
'{}{}'
.
format
(
settings
.
VIDEO_IMAGE_SETTINGS
.
get
(
'DIRECTORY_PREFIX'
,
''
),
filename
)
def
get_video_image_storage
():
def
get_video_image_storage
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment