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 ...@@ -7,6 +7,39 @@ from rest_framework.serializers import ValidationError
from edxval.models import Profile, Video, EncodedVideo 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): class DisplayProfileName(serializers.WritableField):
""" """
......
...@@ -8,10 +8,10 @@ admin.autodiscover() ...@@ -8,10 +8,10 @@ admin.autodiscover()
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^edxval/video/$', views.VideoList.as_view(), url(r'^edxval/video/$', views.VideoList.as_view(),
name="video_view"), name="video-list"),
url(r'^edxval/video/(?P<edx_video_id>\w+)', url(r'^edxval/video/(?P<edx_video_id>\w+)',
views.VideoDetail.as_view(), views.VideoDetail.as_view(),
name="video_detail_view"), name="video-detail"),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
) )
......
...@@ -3,44 +3,49 @@ from rest_framework.response import Response ...@@ -3,44 +3,49 @@ from rest_framework.response import Response
from rest_framework import status, generics from rest_framework import status, generics
from edxval.models import Video from edxval.models import Video
from edxval.serializers import VideoSerializer, EncodedVideoSetDeserializer, EncodedVideoSetSerializer from edxval.serializers import (
VideoSerializer, EncodedVideoSetDeserializer, EncodedVideoSetSerializer,
VideoSerializer2,
)
class VideoList(APIView):
""" # class VideoList(APIView):
<<<<<<< HEAD # """
HTTP API for Video and EncodedVideo objects # <<<<<<< HEAD
""" # HTTP API for Video and EncodedVideo objects
# """
def get(self, request, format=None): #
""" # def get(self, request, format=None):
Gets all videos # """
""" # Gets all videos
video = Video.objects.all() # """
serializer = EncodedVideoSetSerializer(video, many=True) # video = Video.objects.all()
return Response(serializer.data) # serializer = EncodedVideoSetSerializer(video, many=True)
# return Response(serializer.data)
def post(self, request, format=None): #
""" # def post(self, request, format=None):
Takes a Video dict of a list of EncodedVideo dicts and creates the objects # """
# 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 # Args:
data_format (str): format of our data (JSON, XML, etc.) # 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) # Returns:
# Response(message, HTTP status)
""" #
serializer = EncodedVideoSetDeserializer(data=request.DATA) # """
if serializer.is_valid(): # serializer = EncodedVideoSetDeserializer(data=request.DATA)
serializer.save() # if serializer.is_valid():
return Response("Success", status=status.HTTP_201_CREATED) # serializer.save()
else: # return Response("Success", status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) # 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): class VideoDetail(generics.RetrieveUpdateDestroyAPIView):
""" """
...@@ -48,4 +53,4 @@ class VideoDetail(generics.RetrieveUpdateDestroyAPIView): ...@@ -48,4 +53,4 @@ class VideoDetail(generics.RetrieveUpdateDestroyAPIView):
""" """
lookup_field = "edx_video_id" lookup_field = "edx_video_id"
queryset = Video.objects.all() 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