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
b87594b0
Commit
b87594b0
authored
Apr 14, 2017
by
Mushtaq Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More changes
parent
7c491711
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
41 deletions
+67
-41
edxval/api.py
+23
-5
edxval/models.py
+4
-34
edxval/settings.py
+2
-2
edxval/utils.py
+38
-0
No files found.
edxval/api.py
View file @
b87594b0
...
...
@@ -9,12 +9,14 @@ from lxml.etree import Element, SubElement
from
enum
import
Enum
from
django.core.exceptions
import
ValidationError
from
django.core.files.base
import
ContentFile
from
edxval.models
import
Video
,
EncodedVideo
,
CourseVideo
,
Profile
,
VideoImage
from
edxval.serializers
import
VideoSerializer
from
utils
import
get_video_image_storage
logger
=
logging
.
getLogger
(
__name__
)
# pylint: disable=C0103
from
django.core.files.base
import
ContentFile
class
ValError
(
Exception
):
...
...
@@ -183,17 +185,33 @@ def update_video_status(edx_video_id, status):
video
.
save
()
def
update_video_image
(
edx_video_id
,
course_id
,
serialized_data
):
def
get_video_image_url
(
video_image
,
image_filename
=
None
):
"""
Returns video image url.
"""
storage
=
get_video_image_storage
()
# TODO: Is getting file path using video_image.image.name a good way? or Do we need to get file path using
# video_image_path_name(video_image, file_name)
file_name
=
video_image
.
image
.
name
video_image_url
=
storage
.
url
(
file_name
)
return
video_image_url
def
update_video_image
(
edx_video_id
,
course_id
,
serialized_data
,
file_name
):
"""
Update video image for an existing video.
Args:
edx_video_id: ID of the video
edx_video_id: ID of the video.
course_id: ID of course.
serialized_data: Serialized data of image for video.
file_name: File name of the image file.
Raises:
Raises ValVideoNotFoundError if the video cannot be retrieved.
"""
# TODO: Is sending file name a good way ?
try
:
video
=
_get_video
(
edx_video_id
)
...
...
@@ -207,9 +225,9 @@ def update_video_image(edx_video_id, course_id, serialized_data):
video
=
video
,
course_id
=
course_id
)
video_image
.
image
.
save
(
''
,
ContentFile
(
serialized_data
))
video_image
.
image
.
save
(
file_name
,
ContentFile
(
serialized_data
))
video_image
.
save
()
return
get_video_image_url
(
video_image
,
file_name
)
def
create_profile
(
profile_name
):
...
...
edxval/models.py
View file @
b87594b0
...
...
@@ -13,12 +13,12 @@ invalid profile_name will be returned.
import
logging
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.storage
import
get_storage_class
from
utils
import
video_image_path_name
,
get_video_image_storage
logger
=
logging
.
getLogger
(
__name__
)
# pylint: disable=C0103
...
...
@@ -74,36 +74,6 @@ class Profile(models.Model):
return
self
.
profile_name
def
_create_path
(
directory
,
filename
):
"""
Returns the full path for the given directory and filename.
"""
return
'{}-{}'
.
format
(
directory
,
filename
)
def
_directory_name
(
edx_video_id
):
"""
Returns the directory name for the given edx_video_id.
"""
return
'{}{}'
.
format
(
settings
.
VIDEO_THUMBNAIL_SETTINGS
.
get
(
'DIRECTORY_PREFIX'
,
''
),
edx_video_id
)
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
(
thumbnail_model
.
video_id
),
filename
)
def
get_video_thumbnail_storage
():
"""
Return the configured django storage backend.
"""
return
get_storage_class
(
settings
.
VIDEO_THUMBNAIL_SETTINGS
.
get
(
'STORAGE_CLASS'
),
)(
**
settings
.
VIDEO_THUMBNAIL_SETTINGS
.
get
(
'STORAGE_KWARGS'
,
{}))
class
CustomizableFileField
(
models
.
ImageField
):
"""
Subclass of FileField that allows custom settings to not
...
...
@@ -114,8 +84,8 @@ class CustomizableFileField(models.ImageField):
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
kwargs
.
update
(
dict
(
upload_to
=
video_
thumbnail
_path_name
,
storage
=
get_video_
thumbnail
_storage
(),
upload_to
=
video_
image
_path_name
,
storage
=
get_video_
image
_storage
(),
max_length
=
500
,
# allocate enough for filepath
blank
=
True
,
null
=
True
...
...
edxval/settings.py
View file @
b87594b0
...
...
@@ -180,9 +180,9 @@ LOGGING = {
COURSE_KEY_PATTERN
=
r'(?P<course_key_string>[^/+]+(/|\+)[^/+]+(/|\+)[^/]+)'
COURSE_ID_PATTERN
=
COURSE_KEY_PATTERN
.
replace
(
'course_key_string'
,
'course_id'
)
VIDEO_
THUMBNAIL
_SETTINGS
=
dict
(
VIDEO_
IMAGE
_SETTINGS
=
dict
(
# Backend storage
# STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage',
# STORAGE_KWARGS=dict(bucket='video-i
n
age-test-bucket'),
# STORAGE_KWARGS=dict(bucket='video-i
m
age-test-bucket'),
DIRECTORY_PREFIX
=
'videoimage/'
,
)
edxval/utils.py
0 → 100644
View file @
b87594b0
"""
Util methods to be used in api and models.
"""
from
django.conf
import
settings
from
django.core.files.storage
import
get_storage_class
def
_create_path
(
directory
,
filename
):
"""
Returns the full path for the given directory and filename.
"""
return
'{}-{}'
.
format
(
directory
,
filename
)
def
_directory_name
(
edx_video_id
):
"""
Returns the directory name for the given edx_video_id.
"""
return
'{}{}'
.
format
(
settings
.
VIDEO_IMAGE_SETTINGS
.
get
(
'DIRECTORY_PREFIX'
,
''
),
edx_video_id
)
def
video_image_path_name
(
image_model
,
filename
):
# pylint:disable=unused-argument
"""
Returns path name to use for the given Video instance.
"""
return
_create_path
(
_directory_name
(
image_model
.
video
.
edx_video_id
),
filename
)
def
get_video_image_storage
():
"""
Return the configured django storage backend.
"""
return
get_storage_class
(
settings
.
VIDEO_IMAGE_SETTINGS
.
get
(
'STORAGE_CLASS'
),
)(
**
settings
.
VIDEO_IMAGE_SETTINGS
.
get
(
'STORAGE_KWARGS'
,
{}))
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