def get(self, request, title):
     logger.info("GET Search movies with title %s" % (title))
     movies = Movie.objects.filter(name=title)
     if movies:
         return get_movie_list_handler.handle_request(movies)
     else:
         return Response("No Entry found",
                         status.HTTP_204_NO_CONTENT)
 def get(self, request):
     logger.info("Received request to GET Movies list")
     movies = Movie.objects.all()
     if movies.count() > 0:
         return get_movie_list_handler.handle_request(movies)
     else:
         logger.info("Database is Empty")
         return Response("No Entries in the Database",
                         status.HTTP_204_NO_CONTENT)
Exemple #3
0
 def get(self, request):
     logger.info("Received request to GET Movies list")
     movies = Movie.objects.all()
     if movies.count() > 0:
         return get_movie_list_handler.handle_request(movies)
     else:
         logger.info("Database is Empty")
         return Response("No Entries in the Database",
                         status.HTTP_204_NO_CONTENT)
Exemple #4
0
def handle_request(data):
    try:
        movie, created = Movie.objects.get_or_create(name=data["name"])
        if not created:
            logger.info("Movie name already exists")
            return Response("Movie Already Exists",
                            status.HTTP_400_BAD_REQUEST) 
        movie.director, created = Director.objects.get_or_create(name=data["director"])
        movie.imdb_score = data["imdb_score"]
        movie.popularity = data["99popularity"]
        movie.save()
        try:
            for genre in data["genre"]:
                genre = genre.strip(" ")
                genre_instance, created = Genre.objects.get_or_create(name=genre)
                movie.genre.add(genre_instance)
        except Exception:
            movie.delete()
            logger.info(e)
            logger.info(" Caught Exception Genre is Missing")
            return Response("Missing parameter genre", status.HTTP_400_BAD_REQUEST)
        return Response(handle_response([movie]))
    except Exception, e:
        logger.error(e)
        logger.info("Received request to get Movies list")
        return Response("Bad request", status.HTTP_400_BAD_REQUEST)
 def get(self, request, genre):
     try:
         logger.info("GET Search movies with Genre name %s" % (genre))
         genre_instance, created = Genre.objects.get_or_create(name=genre)
         movies = Movie.objects.filter(genre=genre_instance)
         if movies.count() > 0:
             return Response(handle_response(movies))
         else:
             logger.info("No results matching the search query")
             return Response("No Results matching the search query",
                             status.HTTP_204_NO_CONTENT)
     except Exception, e:
         logger.error(e)
         return Response("Error", status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #6
0
 def get(self, request, genre):
     try:
         logger.info("GET Search movies with Genre name %s" % (genre))
         genre_instance, created = Genre.objects.get_or_create(name=genre)
         movies = Movie.objects.filter(genre=genre_instance)
         if movies.count() > 0:
             return Response(handle_response(movies))
         else:
             logger.info("No results matching the search query")
             return Response("No Results matching the search query",
                             status.HTTP_204_NO_CONTENT)
     except Exception, e:
         logger.error(e)
         return Response("Error", status.HTTP_500_INTERNAL_SERVER_ERROR)
 def get(self, request, director):
     logger.info("GET Search movies with director name %s" % (director))
     try:
         director_instance, created = Director.objects.get_or_create(name=director)
         movies = Movie.objects.filter(director  =director_instance)
         if movies.count() > 0:
             return Response(handle_response(movies))
         else:
             logger.info("No results matching the search query")
             return Response("No Results matching the search query",
                             status.HTTP_204_NO_CONTENT)
     except Exception, e:
         print e
         logger.error(e)
         return Response("Error", status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #8
0
def handle_request(movies):
    try:
        movie_list = []
        for movie in movies:
            each_movie = {}
            each_movie["name"] = movie.name
            each_movie["director"] = movie.director.name
            each_movie["imdb_score"] = movie.imdb_score
            each_movie["99popularity"] = movie.popularity
            genre_list = []
            for genre in movie.genre.all():
                genre_list.append(genre.name)
            each_movie["genre"] = genre_list
            movie_list.append(each_movie)
        logger.info("Displaying the list of Movies")
        return Response(movie_list)
    except Exception, e:
        logger.info("Caught exception while GET movie List")
        logger.error(e)
 def delete(self, request, title):
     logger.info("DELETE delete movie with title %s" % (title))
     movie = Movie.objects.filter(name=title)
     movie.delete()
     Response("Movie Deleted", status.HTTP_200_OK)
 def put(self, request, title):
     data = request.DATA
     logger.info("PUT Edit movie with title %s" % (title))
     put_movie_edit_handler.handle_request(data, title)
 def post(self, request):
     logger.info("Received request to POST new Movie")
     data = request.DATA
     return post_movie_list_handler.handle_request(data)
Exemple #12
0
 def post(self, request):
     logger.info("Received request to POST new Movie")
     data = request.DATA
     return post_movie_list_handler.handle_request(data)