예제 #1
0
def new_movie(category_id):
    """
        Handle requests to create a new movie for specified category

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

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

    movie_category = get_movie_category_by_id(category_id)

    if request.method == "POST":
        create_movie(request.form, movie_category.id, movie_category, session[SESSION_USER_ID])
        flash("Movie was successfully added.", "success")
        return redirect(url_for("show_movies", category_id=category_id))
    else:
        return render_template("new_movie.html", title="New Movie", movie_category=movie_category)
예제 #2
0
def show_movies(category_id):
    """
        Show the movies for a specified movie category

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

    movie_categories = get_movie_categories()
    movie_category = get_movie_category_by_id(category_id)
    movies = get_movies_by_category(category_id)

    print session.get(SESSION_USERNAME)

    if SESSION_USERNAME not in session:
        return render_template("movies_public.html", title="Movies", movie_category=movie_category, movies=movies,
                               movie_categories=movie_categories)
    else:
        return render_template("movies.html", title="Movies", movie_category=movie_category, movies=movies,
                               movie_categories=movie_categories)