def home(): postForm = PostForm() if postForm.validate_on_submit(): append_client_history(postForm.number.data) for ind, val in enumerate(session['guess']): update_physic(physics[ind], val, postForm.number.data) clear_physic_guess() return render_template('index.html', physics=physics, postForm=postForm)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Kirjoituksesi on lisäty!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='Uusi kirjoitus', form=form)
def animepage(animeTitle): posts = recentPost() suggestedAnime = SuggestedContent(current_user) form = PostForm() postValidation = "" animes = AnimeSeries.query.filter(AnimeSeries.animeTitle == animeTitle).first() userRating = UserRating.query.filter(UserRating.animeseries_id == animes.id).all() animeRating = animes.scored try: if form.validate_on_submit(): post = Post(animeseries_id=animes.id, title=form.title.data, content=form.content.data, author=current_user) fav = UserRating(user_id=current_user.id, animeseries_id=animes.id, rating=form.rating.data) try: rating=int(form.rating.data) if rating >= 8: animes.favorites.append(current_user) elif rating < 8: meh = UserPassList(user_id=current_user.id, animeseries_id=animes.id) db.session.add(meh) scored, scoredBy, rating = float(animes.scored), float(animes.scoredBy), float(rating) scored, scoredBy = RatingCalculation(rating, scored, scoredBy) scored, scoredBy = str(round(scored, 2)), str(scoredBy) animes.scored, animes.scoredBy = scored, scoredBy except: print("error2") db.session.add(post) db.session.add(fav) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('animepage', animeTitle=animeTitle)) except: print("error") posts2 = Post.query.filter_by(animeseries_id = animes.id).all() try: for post in posts2: if post.user_id == current_user.id: postValidation = "exists" except: print("No user ID found") genreList = getGenre(animes) mediaList = getMedia(animes) producerList = getProducer(animes) studioList = getStudio(animes) image_file = url_for('static', filename='anime_thumbnail/downloads/') image_file2 = url_for('static', filename='gallery_thumbnail/') return render_template('animepage.html', animes=animes, image_file=image_file, image_file2=image_file2, posts=posts, genreList=genreList, mediaList=mediaList, producerList=producerList, studioList=studioList, form=form, animeRating=animeRating, postValidation=postValidation, userRating=userRating, suggestedAnime=suggestedAnime, posts2=posts2)
def post(post_id): post = Post.query.get_or_404(post_id) post_form = PostForm() if post_form.validate_on_submit(): if post_form.title.data and post_form.content.data: post.title = post_form.title.data post.content = post_form.content.data db.session.commit() flash('Your post has been updated', 'success') return redirect(url_for('home')) elif request.method == 'GET': post_form.title.data = post.title post_form.content.data = post.content return render_template('post.html',title='Update post',post = post,form=post_form,legend='Update post')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method =='GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form = form, legend='Update Post')
def new_post(): form = PostForm() if form.validate_on_submit(): media = save_media(form.media.data, 'media') post = Post(content=form.content.data, media=media, author=current_user) db.session.add(post) db.session.commit() flash("Posted successfully", 'success') return redirect(url_for('home')) return render_template("new_post.html", title="Instaclone", form=form, get_file_url=get_file_url)
def new_post(): posts = recentPost() image_file = url_for('static', filename='anime_thumbnail/downloads/') suggestedAnime = SuggestedContent(current_user) form = PostForm() try: if form.validate_on_submit(): post = Post(animeseries_id=form.animeseries_id.data, title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('home')) except: print("error") return render_template('create_post.html', title='New post', form=form, legend='New Post', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
def new_post(): form = PostForm() if form.validate_on_submit(): if form.picture.data: image_file = save_picture_post(form.picture.data) image_file = url_for('static', filename='mile_pics/' + image_file) post = Post(title=form.title.data, content=form.content.data, author=current_user, image_file=form.picture.data) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def update_post(post_id): posts = recentPost() image_file = url_for('static', filename='anime_thumbnail/downloads/') suggestedAnime = SuggestedContent(current_user) post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update post', form=form, legend='Update Post', suggestedAnime=suggestedAnime, image_file=image_file, posts=posts)
def edit(id): form = PostForm() post = Post.query.get_or_404(id) if request.method == "POST": post.title = form.title.data post.content = form.content.data db.session.commit() return redirect(url_for("posts")) elif request.method == "GET": form.title.data = post.title form.content.data = post.content return render_template("add.html", form=form, post=post)
def newpost(): form = PostForm() if request.method == "POST": post_title = form.title.data post_content = form.content.data new_task = Post(title=post_title, content=post_content, author=current_user) db.session.add(new_task) db.session.commit() return redirect("/posts") else: return render_template("add.html", title="add post", form=form)
def close_todo(todo_id): todo_id = str(todo_id) todo_dic = todos.get(todo_id) form = PostForm() if request.method == "POST": today = str(datetime.date.today()) # result if form.result.data: todos[todo_id]["result"] = [form.result.data, today] todos[todo_id]["status"] = "closed" dump_todos_to_json() return redirect("/open") return render_template("close.html", form=form, todo=todo_dic)
def edit_todo(todo_id): todo_id = str(todo_id) todo_dic = todos.get(todo_id) form = PostForm() if request.method == "POST": today = str(datetime.date.today()) todos[todo_id]["title"] = form.title.data if form.comment_1.data: todos[todo_id]["comments"][0][0] = form.comment_1.data if form.comment_2.data: todos[todo_id]["comments"][1][0] = form.comment_2.data if form.comment_3.data: todos[todo_id]["comments"][2][0] = form.comment_3.data if form.comment_4.data: todos[todo_id]["comments"][3][0] = form.comment_4.data if form.comment_5.data: todos[todo_id]["comments"][4][0] = form.comment_5.data if form.comment_6.data: todos[todo_id]["comments"][5][0] = form.comment_6.data if form.comment_7.data: todos[todo_id]["comments"][6][0] = form.comment_7.data if form.comment_8.data: todos[todo_id]["comments"][7][0] = form.comment_8.data if form.comment_9.data: todos[todo_id]["comments"][8][0] = form.comment_9.data if form.comment_10.data: todos[todo_id]["comments"][9][0] = form.comment_10.data if form.comment_11.data: todos[todo_id]["comments"][10][0] = form.comment_11.data if form.comment_12.data: todos[todo_id]["comments"][11][0] = form.comment_12.data if form.comment_13.data: todos[todo_id]["comments"][12][0] = form.comment_13.data if form.comment_14.data: todos[todo_id]["comments"][13][0] = form.comment_14.data if form.comment_15.data: todos[todo_id]["comments"][14][0] = form.comment_15.data if form.comment_16.data: todos[todo_id]["comments"][15][0] = form.comment_16.data if form.comment_17.data: todos[todo_id]["comments"][16][0] = form.comment_17.data if form.comment_18.data: todos[todo_id]["comments"][17][0] = form.comment_18.data if form.comment_19.data: todos[todo_id]["comments"][18][0] = form.comment_19.data if form.comment_20.data: todos[todo_id]["comments"][19][0] = form.comment_20.data # new_comment if form.new_comment.data: todos[todo_id]["comments"].append([form.new_comment.data, today]) # reminder if form.reminder.data: todos[todo_id]["rem_time"] = str(form.reminder.data) new_tags = form.tags.data lnew_tags_temp = new_tags.replace(" ", ",").split(",") lnew_tags = list(filter(None, lnew_tags_temp)) todos[todo_id]["tags"] = lnew_tags dump_todos_to_json() return redirect("/open") return render_template("edit.html", form=form, todo=todo_dic)