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
04bd5191
Commit
04bd5191
authored
Mar 31, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MA-410 Add course_id on import for existing VAL entry.
parent
cb9cf1a3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
edxval/api.py
+12
-5
edxval/models.py
+15
-1
edxval/serializers.py
+1
-0
edxval/tests/test_api.py
+6
-1
No files found.
edxval/api.py
View file @
04bd5191
...
@@ -428,21 +428,31 @@ def import_from_xml(xml, edx_video_id, course_id=None):
...
@@ -428,21 +428,31 @@ def import_from_xml(xml, edx_video_id, course_id=None):
if
xml
.
tag
!=
'video_asset'
:
if
xml
.
tag
!=
'video_asset'
:
raise
ValCannotCreateError
(
'Invalid XML'
)
raise
ValCannotCreateError
(
'Invalid XML'
)
if
Video
.
objects
.
filter
(
edx_video_id
=
edx_video_id
)
.
exists
():
# If video with edx_video_id already exists, associate it with the given course_id.
try
:
video
=
Video
.
objects
.
get
(
edx_video_id
=
edx_video_id
)
logger
.
info
(
logger
.
info
(
"edx_video_id '
%
s' present in course '
%
s' not imported because it exists in VAL."
,
"edx_video_id '
%
s' present in course '
%
s' not imported because it exists in VAL."
,
edx_video_id
,
edx_video_id
,
course_id
,
course_id
,
)
)
if
course_id
:
CourseVideo
.
create_with_validation
(
video
=
video
,
course_id
=
course_id
)
return
return
except
ValidationError
as
err
:
logger
.
exception
(
err
.
message
)
raise
ValCannotCreateError
(
err
.
message_dict
)
except
Video
.
DoesNotExist
:
pass
# Video with edx_video_id did not exist, so create one from xml data.
data
=
{
data
=
{
'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'
),
'status'
:
'imported'
,
'status'
:
'imported'
,
'encoded_videos'
:
[],
'encoded_videos'
:
[],
'courses'
:
[],
'courses'
:
[
course_id
]
if
course_id
else
[
],
}
}
for
encoded_video_el
in
xml
.
iterfind
(
'encoded_video'
):
for
encoded_video_el
in
xml
.
iterfind
(
'encoded_video'
):
profile_name
=
encoded_video_el
.
get
(
'profile'
)
profile_name
=
encoded_video_el
.
get
(
'profile'
)
...
@@ -461,7 +471,4 @@ def import_from_xml(xml, edx_video_id, course_id=None):
...
@@ -461,7 +471,4 @@ def import_from_xml(xml, edx_video_id, course_id=None):
'file_size'
:
encoded_video_el
.
get
(
'file_size'
),
'file_size'
:
encoded_video_el
.
get
(
'file_size'
),
'bitrate'
:
encoded_video_el
.
get
(
'bitrate'
),
'bitrate'
:
encoded_video_el
.
get
(
'bitrate'
),
})
})
if
course_id
:
data
[
'courses'
]
.
append
(
course_id
)
create_video
(
data
)
create_video
(
data
)
edxval/models.py
View file @
04bd5191
...
@@ -19,6 +19,20 @@ from django.core.urlresolvers import reverse
...
@@ -19,6 +19,20 @@ from django.core.urlresolvers import reverse
URL_REGEX
=
r'^[a-zA-Z0-9\-_]*$'
URL_REGEX
=
r'^[a-zA-Z0-9\-_]*$'
class
ModelFactoryWithValidation
(
object
):
"""
A Model mixin that provides validation-based factory methods.
"""
@classmethod
def
create_with_validation
(
cls
,
*
args
,
**
kwargs
):
"""
Factory method that creates and validates the model object before it is saved.
"""
ret_val
=
cls
(
*
args
,
**
kwargs
)
ret_val
.
full_clean
()
ret_val
.
save
()
class
Profile
(
models
.
Model
):
class
Profile
(
models
.
Model
):
"""
"""
Details for pre-defined encoding format
Details for pre-defined encoding format
...
@@ -90,7 +104,7 @@ class Video(models.Model):
...
@@ -90,7 +104,7 @@ class Video(models.Model):
return
qset
return
qset
class
CourseVideo
(
models
.
Model
):
class
CourseVideo
(
models
.
Model
,
ModelFactoryWithValidation
):
"""
"""
Model for the course_id associated with the video content.
Model for the course_id associated with the video content.
...
...
edxval/serializers.py
View file @
04bd5191
...
@@ -83,6 +83,7 @@ class CourseSerializer(serializers.RelatedField):
...
@@ -83,6 +83,7 @@ class CourseSerializer(serializers.RelatedField):
course_video
.
full_clean
(
exclude
=
[
"video"
])
course_video
.
full_clean
(
exclude
=
[
"video"
])
return
course_video
return
course_video
class
VideoSerializer
(
serializers
.
ModelSerializer
):
class
VideoSerializer
(
serializers
.
ModelSerializer
):
"""
"""
Serializer for Video object
Serializer for Video object
...
...
edxval/tests/test_api.py
View file @
04bd5191
...
@@ -860,7 +860,12 @@ class ImportTest(TestCase):
...
@@ -860,7 +860,12 @@ class ImportTest(TestCase):
self
.
assertFalse
(
self
.
assertFalse
(
video
.
encoded_videos
.
filter
(
profile__profile_name
=
constants
.
PROFILE_DESKTOP
)
.
exists
()
video
.
encoded_videos
.
filter
(
profile__profile_name
=
constants
.
PROFILE_DESKTOP
)
.
exists
()
)
)
self
.
assertFalse
(
video
.
courses
.
filter
(
course_id
=
new_course_id
)
.
exists
())
self
.
assertTrue
(
video
.
courses
.
filter
(
course_id
=
new_course_id
)
.
exists
())
def
test_existing_video_with_invalid_course_id
(
self
):
xml
=
self
.
make_import_xml
(
video_dict
=
constants
.
VIDEO_DICT_FISH
)
with
self
.
assertRaises
(
ValCannotCreateError
):
api
.
import_from_xml
(
xml
,
edx_video_id
=
constants
.
VIDEO_DICT_FISH
[
"edx_video_id"
],
course_id
=
"x"
*
300
)
def
test_unknown_profile
(
self
):
def
test_unknown_profile
(
self
):
profile
=
"unknown_profile"
profile
=
"unknown_profile"
...
...
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