def delete_review_admin(): users.require_admin() users.check_csrf() id = int(request.form["review_id"]) movie_id = request.form["movie_id"] reviews.delete_review(id) return redirect("/movie_page/" + str(movie_id))
def admins(): users.require_admin() admins = users.list_admins() number_of_admins = users.get_number_of_admins() return render_template("admins.html", admins=admins, number_of_admins=number_of_admins)
def suggestion_page(): users.require_admin() suggestion_list = suggestions.get_suggestions() number_of_suggestions = suggestions.get_number_of_suggestions() return render_template("suggestions.html", suggestions=suggestion_list, number_of_suggestions=number_of_suggestions)
def accept(): users.require_admin() users.check_csrf() id = request.form["id"] if suggestions.suggested_movie_exists(id): return render_template("suggestions_issue.html", message="Tämän niminen elokuva on jo olemassa.") suggestions.accept(id) return redirect("/suggestions")
def delete_movie_from_category(): users.require_admin() users.check_csrf() movie_id = request.form["movie_id"] category_id = request.form["category_id"] if categories.delete_movie_in_category(movie_id, category_id): return redirect("/category_page/" + str(category_id)) else: return render_template( "category_issue.html", message="Elokuvan poistaminen kategoriasta epäonnistui", id=category_id)
def movie_to_category(): users.require_admin() users.check_csrf() category_id = request.form["category_id"] movie_name = request.form["movie_name"] if categories.check_movie_in_category(movie_name, category_id): return render_template("category_issue.html", message="Elokuva on jo tässä kategoriassa", id=category_id) if not movies.check_if_movie_exists(movie_name): return render_template("category_issue.html", message="Elokuvaa ei löydy", id=category_id) elif categories.movie_to_category(category_id, movie_name): return redirect("/category_page/" + str(category_id)) else: return render_template("category_issue.html", message="Elokuvan lisääminen ei onnistunut", id=category_id)
def add_movie(): users.require_admin() if request.method == "GET": return render_template("add_movie.html") if request.method == "POST": users.check_csrf() name = request.form["name"] if len(name) < 1 or len(name) > 177: return render_template( "add_movie_error.html", message="Elokuvan nimi pitää olla 1-177 merkkiä.") if movies.check_if_movie_exists(name): return render_template( "add_movie_error.html", message="Tämän niminen elokuva on jo olemassa.") year = request.form["year"] if len(year) != 4: return render_template("add_movie_error.html", message="Vuosiluvussa pitää olla 4 numeroa") if int(year) > 2021: return render_template( "add_movie_error.html", message="Julkaisu vuosi ei voi olla uudempi kuin 2021") genres = request.form["genre"] if genres == "": return render_template( "add_movie_error.html", message="Elokuvalla pitää olla edes yksi genre") description = request.form["description"] if description == "": return render_template("add_movie_error.html", message="Elokuvalla pitää olla kuvaus") leading_roles = request.form["leading_roles"] if leading_roles == "": return render_template( "add_movie_error.html", message="Elokuvalla pitää olla edes yksi päärooli") if movies.add_movie(name, year, genres, description, leading_roles): return redirect("/") else: return render_template("add_movie_error.html", message="Elokuvan lisäys epäonnistui")
def delete_movie(): users.require_admin() users.check_csrf() movie_id = request.form["movie_id"] movies.delete_movie(movie_id) return redirect("/")
def add_category(): users.require_admin() users.check_csrf() name = request.form["category_name"] categories.add_category(name) return redirect("/categories")
def delete_category(): users.require_admin() users.check_csrf() category_id = request.form["category_id"] categories.delete_category(category_id) return redirect("/categories")
def decline(): users.require_admin() users.check_csrf() id = request.form["id"] suggestions.decline(id) return redirect("/suggestions")