Commit 266fa9f5 by David Ormsbee

First pass at using generic views for Video

parent 112da93f
......@@ -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):
"""
......
......@@ -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)),
)
......
......@@ -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 = VideoSerializer2
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