Beispiel #1
0
def add_movie(request):
    data = {
        "add_movie_form": SimpleInput(),
    }
    if request.method == "POST":
        form = SimpleInput(request.POST)
        if form.is_valid():
            ia = IMDb()
            movie_info = ia.get_movie(form.cleaned_data['question'])
            if Movie.objects.filter(
                    movie_id=movie_info.movieID):  # if movie in our Db
                movie = Movie.objects.get(movie_id=movie_info.movieID)
                movie.user.add(request.user)
                if not movie.searched:  # if movie has not been searched, scrape locations
                    get_locations(movie)
            else:  # if movie not in our Db add it and scrape locations
                movie = Movie.objects.create(title=movie_info['title'],
                                             movie_id=movie_info.movieID)
                movie.save()
                movie.user.add(request.user)
                get_locations(movie)
            redirect("/movies/")
        else:
            data = {
                "add_movie_form": form,
            }
    return render(request, "add_movie.html", data)
Beispiel #2
0
def search_movie(request):
    data = {"search_movie_form": SimpleInput(), }
    if request.method == "POST":
        form = SimpleInput(request.POST)
        if form.is_valid():
            ia = IMDb()
            movies = ia.search_movie(form.cleaned_data['question'])
            data = {
                'movies': movies
            }
            return render(request, "show_movie.html", data)
        else:
            data = {"search_movie_form": form, }
    return render(request, "search_movie.html", data)
Beispiel #3
0
def search_movie(request):
    data = {
        "search_movie_form": SimpleInput(),
    }
    if request.method == "POST":
        form = SimpleInput(request.POST)
        if form.is_valid():
            ia = IMDb()
            movies = ia.search_movie(form.cleaned_data['question'])
            data = {'movies': movies}
            return render(request, "show_movie.html", data)
        else:
            data = {
                "search_movie_form": form,
            }
    return render(request, "search_movie.html", data)
Beispiel #4
0
def add_movie(request):
    data = {"add_movie_form": SimpleInput(), }
    if request.method == "POST":
        form = SimpleInput(request.POST)
        if form.is_valid():
            ia = IMDb()
            movie_info = ia.get_movie(form.cleaned_data['question'])
            if Movie.objects.filter(movie_id=movie_info.movieID):       # if movie in our Db
                movie = Movie.objects.get(movie_id=movie_info.movieID)
                movie.user.add(request.user)
                if not movie.searched:                                  # if movie has not been searched, scrape locations
                    get_locations(movie)
            else:                                                       # if movie not in our Db add it and scrape locations
                movie = Movie.objects.create(title=movie_info['title'], movie_id=movie_info.movieID)
                movie.save()
                movie.user.add(request.user)
                get_locations(movie)
            redirect("/movies/")
        else:
            data = {"add_movie_form": form, }
    return render(request, "add_movie.html", data)