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
266fa9f5
Commit
266fa9f5
authored
Aug 05, 2014
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First pass at using generic views for Video
parent
112da93f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
41 deletions
+79
-41
edxval/serializers.py
+33
-0
edxval/urls.py
+2
-2
edxval/views.py
+44
-39
No files found.
edxval/serializers.py
View file @
266fa9f5
...
...
@@ -7,6 +7,39 @@ from rest_framework.serializers import ValidationError
from
edxval.models
import
Profile
,
Video
,
EncodedVideo
class
ProfileSerializer2
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Profile
fields
=
(
"profile_name"
,
"extension"
,
"width"
,
"height"
)
class
EncodedVideoSerializer2
(
serializers
.
ModelSerializer
):
profile
=
serializers
.
SlugRelatedField
(
slug_field
=
"profile_name"
)
class
Meta
:
model
=
EncodedVideo
fields
=
(
"created"
,
"modified"
,
"url"
,
"file_size"
,
"bitrate"
,
"profile"
,
)
class
VideoSerializer2
(
serializers
.
HyperlinkedModelSerializer
):
encoded_videos
=
EncodedVideoSerializer2
(
many
=
True
)
class
Meta
:
model
=
Video
lookup_field
=
"edx_video_id"
class
DisplayProfileName
(
serializers
.
WritableField
):
"""
...
...
edxval/urls.py
View file @
266fa9f5
...
...
@@ -8,10 +8,10 @@ admin.autodiscover()
urlpatterns
=
patterns
(
''
,
url
(
r'^edxval/video/$'
,
views
.
VideoList
.
as_view
(),
name
=
"video
_view
"
),
name
=
"video
-list
"
),
url
(
r'^edxval/video/(?P<edx_video_id>\w+)'
,
views
.
VideoDetail
.
as_view
(),
name
=
"video
_detail_view
"
),
name
=
"video
-detail
"
),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
)
...
...
edxval/views.py
View file @
266fa9f5
...
...
@@ -3,44 +3,49 @@ from rest_framework.response import Response
from
rest_framework
import
status
,
generics
from
edxval.models
import
Video
from
edxval.serializers
import
VideoSerializer
,
EncodedVideoSetDeserializer
,
EncodedVideoSetSerializer
class
VideoList
(
APIView
):
"""
<<<<<<< HEAD
HTTP API for Video and EncodedVideo objects
"""
def
get
(
self
,
request
,
format
=
None
):
"""
Gets all videos
"""
video
=
Video
.
objects
.
all
()
serializer
=
EncodedVideoSetSerializer
(
video
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
post
(
self
,
request
,
format
=
None
):
"""
Takes a Video dict of a list of EncodedVideo dicts and creates the objects
Args:
request (object): Object where we get our information for POST
data_format (str): format of our data (JSON, XML, etc.)
Returns:
Response(message, HTTP status)
"""
serializer
=
EncodedVideoSetDeserializer
(
data
=
request
.
DATA
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
Response
(
"Success"
,
status
=
status
.
HTTP_201_CREATED
)
else
:
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
from
edxval.serializers
import
(
VideoSerializer
,
EncodedVideoSetDeserializer
,
EncodedVideoSetSerializer
,
VideoSerializer2
,
)
# class VideoList(APIView):
# """
# <<<<<<< HEAD
# HTTP API for Video and EncodedVideo objects
# """
#
# def get(self, request, format=None):
# """
# Gets all videos
# """
# video = Video.objects.all()
# serializer = EncodedVideoSetSerializer(video, many=True)
# return Response(serializer.data)
#
# def post(self, request, format=None):
# """
# Takes a Video dict of a list of EncodedVideo dicts and creates the objects
#
# Args:
# request (object): Object where we get our information for POST
# data_format (str): format of our data (JSON, XML, etc.)
#
# Returns:
# Response(message, HTTP status)
#
# """
# serializer = EncodedVideoSetDeserializer(data=request.DATA)
# if serializer.is_valid():
# serializer.save()
# return Response("Success", status=status.HTTP_201_CREATED)
# else:
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class
VideoList
(
generics
.
ListCreateAPIView
):
queryset
=
Video
.
objects
.
all
()
.
select_related
(
"encoded_videos"
)
lookup_field
=
"edx_video_id"
serializer_class
=
VideoSerializer2
class
VideoDetail
(
generics
.
RetrieveUpdateDestroyAPIView
):
"""
...
...
@@ -48,4 +53,4 @@ class VideoDetail(generics.RetrieveUpdateDestroyAPIView):
"""
lookup_field
=
"edx_video_id"
queryset
=
Video
.
objects
.
all
()
serializer_class
=
VideoSerializer
serializer_class
=
VideoSerializer
2
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