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 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 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 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(id): if request.method == "GET": movie = _fetch_movie(id) if movie is not None: if request.is_xhr: return jsonify({ "service_id": movie.service_id, "title": movie.title, "description": movie.description, "poster": movie.poster, "year": movie.year, "imdb_id": movie.imdb_id, "votes": movie.votes, "in_production": movie.being_made, "produced": movie.already_made, "facebook_uid": movie.facebook_uid, "facebook_name": movie.facebook_name }) voters = _fetch_latest_votes(id) return render_template('single.html', movie=movie, image_path=settings.IMAGE_PATH, voters=voters) if request.method == "POST": form = MovieForm(request.form) if form.validate() is False: for error in form.errors: logging.info(error) return abort(500) if _validate_user(form.facebook_uid.data, form.facebook_token.data): movie = _fetch_movie(form.service_id.data) if movie is None: m = Movie(service_id=form.service_id.data, title=form.title.data, year=form.year.data.split("-")[0], poster=form.poster.data, description=form.description.data, imdb_id=form.imdb_id.data, facebook_uid=form.facebook_uid.data, facebook_name=form.facebook_name.data) m.save() return jsonify(result="success") return abort(500) return abort(404)
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 new_movie(): form = MovieForm(request.form) if request.method == 'POST' and form.validate(): # save the album movie_created = Movie() movie_save_changes(movie_created, form, new=True) flash('Movie created successfully!') return redirect('/movie') return render_template('new_movie.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 add_movie(request): if request.method == "POST": form = MovieForm(request.POST) if form.is_valid(): new_movie = form.save(commit=False) new_movie.user_id = request.user.id new_movie.save() request.user.message_set.create(message="Movie Added !!!") return redirect("movies_list") else: form = MovieForm() return direct_to_template(request, "templates/add_movie.html", {"form": form})
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 dashboard_add_movie(request): context = RequestContext(request) if request.method == 'POST': form = MovieForm(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) obj.uploaded_by = request.user obj.save() return HttpResponseRedirect('/movies/dashboard') return render_to_response("movie_library/dashboard/add_movie.html", {"form": form, 'dashboard_active':'active'}, context) elif request.method == 'GET': form = MovieForm() return render_to_response("movie_library/dashboard/add_movie.html", {"form": form, 'dashboard_active':'active'}, context)
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 movies_edit_form(movie_id): movie = Movies.query.get(movie_id) form = MovieForm() form.title.data = movie.title form.release_date.data = movie.release_date form.image_link.data = movie.image_link return render_template('form_movies.html', form=form)
def add_new_movie(payload): # prepare form to read posted data form = MovieForm(request.form) # create json object to use with backend request new_movie = { 'title': form.title.data, 'movie_category': form.movie_category.data, 'movie_rating': form.movie_rating.data, 'release_date': str(form.release_date.data) } # add movie backend url create_movie_url = BACKEND_URL + '/movies' # make post request to backend api_response = requests.post(create_movie_url, headers=get_headers(), json=new_movie) response_json = api_response.json() # check backend response if (response_json['success'] and response_json['new_movie_id'] > 0): # if addedd successfully, flash success and return to movie's list page flash('Movie created successfully!', 'success') return redirect(url_for('movies')) elif 'error' in response_json: # if there is error in response, abort for error code abort(response_json['error']) else: flash('Something went wrong!!', 'danger') return render_template('pages/movies/add.html', form=form)
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 edit_movie_action(payload, movie_id): # prepare form with posted data form = MovieForm(request.form) # create movie object to use with backend request updated_movie_info = { 'title': form.title.data, 'movie_category': form.movie_category.data, 'movie_rating': form.movie_rating.data, 'release_date': str(form.release_date.data) } # backend to update movie's info edit_movie_url = BACKEND_URL + '/movies/' + str(movie_id) # make patch request api_response = requests.patch(edit_movie_url, headers=get_headers(), json=updated_movie_info) response_json = api_response.json() # check backend response if (response_json['success'] and response_json['updated'] == movie_id): # if updated successfully, flash success and return to movie's info list flash('Movie updated successfully!', 'success') return redirect('/movies/' + str(movie_id)) elif 'error' in response_json: # if there is error in response, abort for error code abort(response_json['error']) else: flash('Something went wrong!!', 'danger') return render_template('pages/movies/edit.html', form=form)
def create_movie_form(): try: form = MovieForm() return render_template('new_movie.html', form=form, data=session['user_info']) except: abort(500)
def addMovie(request): movie_form = MovieForm() movie_form.fields.pop('categories') category_form = CategoryForm() return render(request, 'tommymovies/addMovie.html', { 'movie_form': movie_form, 'category_form': category_form })
def add_movie_form(request): """ Module that adds the data from the page /addmovieform/ if a movie with the same title does not exist :param request: request, HTML Template, movie_listing = the list of Movie objects :return: """ if request.POST: form = MovieForm(request.POST) if form.is_valid(): # Check if the movie already exists in the database check_db = Movie.objects.filter(title=request.POST['title']) if len(check_db) > 0: # If a movie with same name exists the do not enter to DB return render(request, 'movie_exists.html', {'movie_title': request.POST['title']}) else: # Save form and redirect to the success page form.save() return render_to_response( 'add_success.html', {'movie_title': request.POST['title']}) else: form = MovieForm() return render(request, 'add_movie_form.html', {'form': form})
def add(request): if request.method == "POST": form = MovieForm(request.POST) if form.is_valid(): new_movie = Movie.objects.create_movie(**form.cleaned_data) try: genre_id = request.POST.getlist('genre', '') for id in genre_id: new_category = get_object_or_404(Category, id=id) new_movie.categories.add(new_category) except: pass new_movie.save() return HttpResponseRedirect(reverse('tommymovies:history')) else: form = MovieForm() return render(request, 'tommymovies/add.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)
def addMovieSubmit(request): if request.method == "POST": form = MovieForm(request.POST) genre_id = request.POST.get('genre', '') category = get_object_or_404(Category, id=genre_id) if form.is_valid(): new_movie = Movie.objects.create_movie( form.cleaned_data['name'], form.cleaned_data['year'], form.cleaned_data['watched'], form.cleaned_data['watch_date'], form.cleaned_data['p_rating'], form.cleaned_data['imdb_rating'], form.cleaned_data['rt_rating']) new_movie.categories.add(category) new_movie.save() return HttpResponseRedirect(reverse('tommymovies:history')) else: form = MovieForm() return render(request, 'tommymovies/addMovie.html', { 'movie_form': movie_form, 'category_form': category_form })
def edit_movie(payload, movie_id): form = MovieForm() movie = Movie.query.get(movie_id) if not movie: abort(404) if movie: form.name.data = movie.name form.release_date.data = movie.release_date form.image_link.data = movie.image_link form.film_summary.data = movie.film_summary return render_template('forms/edit_movie.html', form=form, movie=movie), 200
def movie(id): if request.method == "GET": movie = _fetch_movie(id) if movie is not None: if request.is_xhr: return jsonify({"service_id":movie.service_id, "title": movie.title, "description": movie.description, "poster": movie.poster, "year": movie.year, "imdb_id": movie.imdb_id, "votes": movie.votes, "in_production": movie.being_made, "produced": movie.already_made, "facebook_uid": movie.facebook_uid, "facebook_name": movie.facebook_name}) voters = _fetch_latest_votes(id) return render_template('single.html', movie=movie, image_path=settings.IMAGE_PATH, voters=voters) if request.method == "POST": form = MovieForm(request.form) if form.validate() is False: for error in form.errors: logging.info(error) return abort(500) if _validate_user(form.facebook_uid.data, form.facebook_token.data): movie = _fetch_movie(form.service_id.data) if movie is None: m = Movie(service_id=form.service_id.data, title=form.title.data, year=form.year.data.split("-")[0], poster=form.poster.data, description=form.description.data, imdb_id=form.imdb_id.data, facebook_uid=form.facebook_uid.data, facebook_name=form.facebook_name.data) m.save() return jsonify(result="success") return abort(500) return abort(404)
def new_movie(request): if request.method == "POST": form = MovieForm(request.POST, request.FILES) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() return redirect(all_statistics) else: form = MovieForm() return render(request, 'movieform.html', {'form': form})
def search(request): """ Module to search the database with the title, genre, or director. Called from the /searchmovie/ :param request: page request :return: request, HTML Template, movie_listing = the list of Movie objects """ if request.GET: movie_listing = [] search_string = "" # Check for each entry in the search form. # Find all the movies that match either one of the search entries if request.GET['title']: for movie_object in Movie.objects.filter( title__contains=request.GET['title']): movie_dict = {'movie_object': movie_object} movie_listing.append(movie_dict) search_string = request.GET['title'] if request.GET['genre']: for movie_object in Movie.objects.filter( genre__contains=request.GET['genre']): movie_dict = {'movie_object': movie_object} movie_listing.append(movie_dict) search_string = " ".join((search_string, request.GET['genre'])) if request.GET['director']: for movie_object in Movie.objects.filter( director__contains=request.GET['director']): movie_dict = {'movie_object': movie_object} movie_listing.append(movie_dict) search_string = " ".join((search_string, request.GET['director'])) if request.GET['language']: for movie_object in Movie.objects.filter( language__contains=request.GET['language']): movie_dict = {'movie_object': movie_object} movie_listing.append(movie_dict) search_string = " ".join((search_string, request.GET['language'])) # Redirect to the results.html page if atleast one movie is found basedon the search strings if len(movie_listing) > 0: return render_to_response('results.html', { 'search_string': search_string, 'movie_listing': movie_listing }) form = MovieForm() return render(request, 'search.html', {'form': form})
def edit_movie_form(payload, movie_id): # perpare form form = MovieForm() # empty movie's info object movie = { 'id': movie_id, 'title': '', 'movie_rating': '', 'movie_category': '', 'release_date': '' } # backend url to read movie's info get_movie_url = BACKEND_URL + '/movies/' + str(movie_id) # make get request to read movie's info api_response = requests.get(get_movie_url, headers=get_headers()) response_json = api_response.json() # check backend response if (response_json['success'] and len(response_json['movie']) > 0): # read movie's info movie = response_json['movie'] # prepare form with movie's info form.title.data = movie['title'] form.movie_rating.data = movie['movie_rating'] form.movie_category.data = movie['movie_category'] # date1 = movie['movie_category'].strftime("%y/%m%d") date = dateutil.parser.parse(movie['release_date']) print(date) form.release_date.data = date elif 'error' in response_json: # if there is error in response, abort for error code abort(response_json['error']) else: flash('Something went wrong!!', 'danger') return redirect(url_for("movies")) return render_template('pages/movies/edit.html', movie=movie, form=form)
def homepage(): # form for user to enter a movie name they come up with form = MovieForm() # if post data is submitted to this route, check it if request.method == 'POST': # check to see if form data under the name of 'movieName' was submitted if request.form.get('movieName'): # the user's film request filmRequest = request.form.get('movieName') filmResults = Movie.query.filter( Movie.title.like("%" + filmRequest + "%")).all() # filmResults = [filmRequest] # stores selection forms for all of the movie results the db returns filmForms = [] # create the selection forms for result in filmResults: filmForms.append( [result.title, SelectMovieForm(movieID=result.uid)]) if filmForms == []: msg = 'Sorry, we couldn\'t find anything. Perhaps try searching again' return render_template('index.html', form=form, filmRequest=filmRequest, msg=msg) return render_template('index.html', form=form, filmRequest=filmRequest, filmForms=filmForms) # if no post data (or satisfactory post data) was submitted, render the base homepage return render_template('index.html', form=form)
def dashboard_add_movie(request): context = RequestContext(request) if request.method == 'POST': form = MovieForm(request.POST, request.FILES) if form.is_valid(): obj = form.save(commit=False) obj.uploaded_by = request.user obj.save() return HttpResponseRedirect('/movies/dashboard') return render_to_response("movie_library/dashboard/add_movie.html", { "form": form, 'dashboard_active': 'active' }, context) elif request.method == 'GET': form = MovieForm() return render_to_response("movie_library/dashboard/add_movie.html", { "form": form, 'dashboard_active': 'active' }, context)
def addByUrl_form(request): form = MovieForm() return render(request, 'tommymovies/urlAdd.html', {'form': form})
def edit_submit(request, movie_id): movie = get_object_or_404(Movie, id=movie_id) if request.method == "POST": form = MovieForm(request.POST) form.data = form.data.copy() category_id_list = [] listgenres = request.POST.getlist('categories') for genre in movie.categories.all(): movie.categories.remove(genre) for genre in listgenres: try: category = get_object_or_404(Category, genre=genre) category_id = str(category.id).encode("utf-8").decode("utf-8") category_id_list.append(category_id) except: pass else: if genre not in movie.categories.all(): movie.categories.add(category) form.data.setlist('categories', category_id_list) try: genre_id = request.POST.get('genre', '') new_category = get_object_or_404(Category, id=genre_id) movie.categories.add(new_category) movie.save() except: pass #hack to avoid '"" is not a valid value for a primary key' error sample_category = get_object_or_404(Category, id=1) sample_category_id = str( sample_category.id).encode("utf-8").decode("utf-8") category_id_list.append(sample_category_id) form.data.setlist('categories', category_id_list) if form.is_valid(): movie.name = form.cleaned_data[ 'name'] #request.POST.get("name", "")# movie.year = form.cleaned_data[ 'year'] #request.POST.get("year", "")# movie.watched = form.cleaned_data[ 'watched'] #request.POST.get("watched", "")# movie.watch_date = form.cleaned_data[ 'watch_date'] #request.POST.get("watch_date", "")# movie.p_rating = form.cleaned_data[ 'p_rating'] #request.POST.get("p_rating", "")# movie.imdb_rating = form.cleaned_data[ 'imdb_rating'] #request.POST.get("imdb_rating", "")# movie.rt_rating = form.cleaned_data[ 'rt_rating'] #request.POST.get("rt_rating", "")# movie.imdb_url = form.cleaned_data[ 'imdb_url'] #request.POST.get("imdb_url", "")# movie.rt_url = form.cleaned_data[ 'rt_url'] #request.POST.get("rt_url", "")# movie.douban_url = form.cleaned_data[ 'douban_url'] #request.POST.get("douban_url", "")# movie.comment = form.cleaned_data[ 'comment'] #request.POST.get("comment", "") movie.save() return render(request, 'tommymovies/movie.html', { 'movie': movie, 'form': form, 'listgenres': listgenres }) else: form = MovieForm(instance=movie) #return render(request, 'tommymovies/movie.html', {'movie': movie }) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))