예제 #1
0
def delete_movie(category_id, movie_id):
    """
        Handle requests to delete a movie for specified category

        :param category_id: The ID of the movie category
        :return: Web page for deleting movie and redirect after deleting the movie
    """

    if SESSION_USERNAME not in session:
        flash("You need to be logged in to perform that action.", "danger")
        return redirect("/login")

    movie_to_delete = get_movie_by_id(movie_id)

    if movie_to_delete.user_id != session[SESSION_USER_ID]:
        flash("You are not authorized to delete this movie. Only the creator of this movie can delete it.",
              "danger")
        return redirect(url_for("show_movies", category_id=category_id))

    if request.method == "POST":
        remove_movie(movie_to_delete)
        flash("Movie was successfully deleted.", "success")
        return redirect(url_for("show_movies", category_id=category_id))
    else:
        return render_template("delete_movie.html", title="Delete Movie", movie=movie_to_delete)
예제 #2
0
def show_movie_json(category_id, movie_id):
    """
        JSON API endpoint for a single movie of a specified movie category

        :param category_id: The ID of the movie category
        :param movie_id: The ID of the movie
        :return: JSON information about a single movie for specified category
    """

    movie = get_movie_by_id(movie_id)
    return jsonify(movie=movie.serialize)
예제 #3
0
def show_movie(category_id, movie_id):
    """
        Show a single movie for a specified movie category

        :param category_id: The ID of the movie category
        :param movie_id: The ID of the movie
        :return: Web page displaying the movie for specified category
    """

    movie = get_movie_by_id(movie_id)
    return render_template("movie.html", title="Movie", movie=movie)