def movie_show(username): """Show Movie Search Form and process it.""" if 'username' not in session or username != session['username']: raise Unauthorized() form = MovieForm() if form.validate_on_submit(): title = request.form['title'] actors = request.form['actors'] plot = request.form['plot'] mdetails = request_movie(title) #update the form data title = mdetails['Title'] actors = mdetails['Actors'] plot = mdetails['Plot'] #Movie Model Blueprint movie = Movie(title=(title), actors=(actors), plot=(plot), username=(username)) db.session.add(movie) db.session.commit() return redirect(f"/users/{movie.username}") else: return render_template("movies/new.html", form=form)
def movie_add(): form = MovieForm() if form.validate_on_submit(): data = form.data # 文件处理 file_url = secure_filename(form.url.data.filename) file_logo = secure_filename(form.logo.data.filename) if not os.path.exists(app.config["UP_DIR"]): os.makedirs(app.config["UP_DIR"]) os.chmod(app.config["UP_DIR"], "rw") url = change_filename(file_url) logo = change_filename(file_logo) form.url.data.save(app.config["UP_DIR"]+url) form.logo.data.save(app.config["UP_DIR"] + logo) # 数据处理 movie = Movie( title=data["title"], url=url, info=data["info"], logo=logo, star=int(data["star"]), playnum=0, commentnum=0, tag_id=int(data["tag_id"]), area=data["area"], release_time=data["release_time"], length=data["length"] ) db.session.add(movie) db.session.commit() flash("添加电影成功! ", 'info') return redirect(url_for("admin.movie_add")) return render_template("admin/movie_add.html", form=form)
def movie_show_main(username): ### search form for view all route form = MovieForm() if form.validate_on_submit(): title = request.form['title'] actors = request.form['actors'] plot = request.form['plot'] mdetails = request_movie(title) #update the form data title = mdetails['Title'] actors = mdetails['Actors'] plot = mdetails['Plot'] #Movie Model Blueprint movie = Movie(title=(title), actors=(actors), plot=(plot), username=username) db.session.add(movie) db.session.commit() return redirect(f"/users/{movie.username}") else: return render_template("movies/new.html", form=form)
def index(): movies = dict() movie_titles = get_movie_names() form = MovieForm() if form.validate_on_submit(): movie1 = form.movie1.data movies[movie_titles[0]] = movie1 movie2 = form.movie2.data movies[movie_titles[1]] = movie2 movie3 = form.movie3.data movies[movie_titles[2]] = movie3 movie4 = form.movie4.data movies[movie_titles[3]] = movie4 movie5 = form.movie5.data movies[movie_titles[4]] = movie5 movie6 = form.movie6.data movies[movie_titles[5]] = movie6 movie7 = form.movie7.data movies[movie_titles[6]] = movie7 movie8 = form.movie8.data movies[movie_titles[7]] = movie8 movie9 = form.movie9.data movies[movie_titles[8]] = movie9 movie10 = form.movie10.data movies[movie_titles[9]] = movie10 print(movies) if form.submit_item_based.data: print("item was true") return redirect(url_for('user_based', result_data=movies)) if form.submit_user_based.data: print("user was true") return redirect(url_for('item_based', result_data=movies)) return render_template('recommender.html', form=form, titles=movie_titles)
def add(): form = MovieForm() if form.validate_on_submit(): name = form.name.data release = form.release.data mv = models.MovieList(name=name, release=release) db.session.add(mv) db.session.commit() return redirect(url_for('index')) return render_template('add.html', form=form)
def post(self): form = MovieForm() if form.validate_on_submit(): print(form.theatername.data) print(form.moviename.data) a = Admin() returnvalue = a.AddAMovieToParticularTheater( form.theatername.data, form.moviename.data) return 1 return 0
def movies1(): movie_name = False form = MovieForm() if form.validate_on_submit(): movie_name = form.movie_name.data form.movie_name.data = '' return render_template( 'movies.html', movie_name=movie_name, form=form, )
def add_movie(): form = MovieForm() if not form.validate_on_submit(): return render_template('new_movie.html', title='Add New Movie', form=form) lang_id = add_language(form.data['language']) movie_attr = [{ 'title': '' }, { 'description': '' }, { 'release_year': 0 }, { 'rental_duration': 0 }, { 'rental_rate': 0.00 }, { 'length': 0 }, { 'replacement_cost': '' }] for attr in movie_attr: for k, v in attr.items(): attr[k] = form.data[k] movie_attr.append({'language_id': lang_id}) param_subs = [] for attr in movie_attr: for k, v in attr.items(): param = (v, ) param_subs.append(param) cur.execute( """ INSERT INTO film (title, description, release_year, rental_duration, rental_rate, length, replacement_cost, language_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """, param_subs) try: confirmation_query = ' & '.join(param_subs[0][0].split(' ')) cur.execute("SELECT * FROM film where fulltext @@ to_tsquery(%s)", (confirmation_query, )) res = cur.fetchall() message = '' if len(res) > 0: conn.commit() message = 'Successfully added movie!' else: message = 'Failed to add movie for some reason. Try again' return render_template('status.html', message=message) except Exception as e: print(e) return redirect(url_for('index'))
def post(self): form = MovieForm() if form.validate_on_submit(): u = User() returnvalue = u.SeatDetails(form.theatername.data, form.moviename.data) if returnvalue: print(returnvalue['movies']) # return 1 return make_response( render_template("MovieDetails.html", form=form, data=returnvalue)) return 0
def movie_edit(id=None): form = MovieForm() form.url.flags.required = False form.logo.flags.required = False form.url.validators = [] form.logo.validators = [] movie = Movie.query.get_or_404(int(id)) # 如果是请求的话填充信息 if request.method == "GET": form.info.data = movie.info form.tag_id.data = movie.tag_id form.star.data = movie.star if form.validate_on_submit(): data = form.data movie_count = Movie.query.filter_by(title=data["title"]).count() if movie_count == 1 and movie.title != data.get("title"): flash("片名已经存在,请重新输入!", "err") return redirect(url_for("admin.movie_edit", id=id)) if not os.path.exists(app.config["UP_DIR"]): os.makedirs(app.config["UP_DIR"]) os.chmod(app.config["UP_DIR"], "rw") if form.url.data.filename != "": file_url = secure_filename(form.url.data.filename) movie.url = change_filename(file_url) form.url.data.save(app.config["UP_DIR"] + movie.url) if form.logo.data.filename != "": file_logo = secure_filename(form.logo.data.filename) movie.logo = change_filename(file_logo) form.logo.data.save(app.config["UP_DIR"] + movie.logo) movie.title = data.get("title") movie.info = data.get("info") movie.star = data.get("star") movie.tag_id = data.get("tag_id") movie.area = data.get("area") movie.release_time = data.get("release_time") movie.length = data.get("length") db.session.add(movie) db.session.commit() flash("修改电影成功! ", 'info') return redirect(url_for("admin.movie_add", id=movie.id)) return render_template("admin/movie_edit.html", form=form, movie=movie)
def movie_form(): form = MovieForm() if request.method == 'POST': if form.validate_on_submit(): m = Movie(title=form.title.data, year=form.year.data, description=form.description.data) db.session.add(m) db.session.commit() url_to_dedirect = url_for('index', id=m.id) return redirect(url_to_dedirect) else: return render_template('movie_form.html', form=form) else: return render_template('movie_form.html', form=form)
def update_movie(username, movie_id): """Show update-movie title and process it.""" movie = Movie.query.get(movie_id) if "username" not in session or movie.username != session['username']: raise Unauthorized() form = MovieForm() if form.validate_on_submit(): movie.title = form.title.data db.session.commit() return redirect(f"/users/{movie.username}") return render_template("/movies/edit.html", form=form, username=username, movie=movie)