Esempio n. 1
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)
Esempio n. 3
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)
def handle_request(data, title):
    try:
        movie = Movie.objects.get(name=title)
        movie.name = data["name"]
        movie.director, created = Director.objects.get_or_create(name=
                                                                 data["director"])
        movie.imdb_score = data["imdb_score"]
        movie.popularity = data["99popularity"]
        movie.save()
        for genre in movie.genre.all():
            movie.genre.remove(genre)
        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, e:
        logger.error(e)
        return {"Bad Request", status.HTTP_400_BAD_REQUEST}
Esempio n. 6
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)