class VideoDetailsView(BaseView): serializer_class = VideoSerializer model = Video @authenticate def get(self, request, id): # Attempt to get the video self.video = self.get_object_or_404(Video.all_objects, id=id) if (self.video.is_private and request.user.id != self.video.user.id) or (self.video.uploaded == False): return self.error_response("Video with id {} not found".format(id), 404) # Serialize the result and return it self.serializer = JamJarVideoSerializer(self.video, context={"request": request}) return self.success_response(self.serializer.data) @authenticate def put(self, request, id): # Attempt to get the video self.video = self.get_object_or_404(self.model, id=id) # Initialize the serializer with our data self.serializer = self.get_serializer(self.video, data=request.data, context={"request": request}) # Validate the data if not self.serializer.is_valid(): return self.error_response(self.serializer.errors, 400) # Errthang looks good. Save it to the db video = self.serializer.save() return self.success_response(self.serializer.data) @authenticate def delete(self, request, id): # Attempt to get the video self.video = self.get_object_or_404(self.model, id=id) # Serialize the result and return it self.video.delete() return self.success_response("Video with id {} successfully deleted.".format(id))
def get(self, request, id): # Attempt to get the video self.video = self.get_object_or_404(Video.all_objects, id=id) if (self.video.is_private and request.user.id != self.video.user.id) or (self.video.uploaded == False): return self.error_response("Video with id {} not found".format(id), 404) # Serialize the result and return it self.serializer = JamJarVideoSerializer(self.video, context={"request": request}) return self.success_response(self.serializer.data)