def new_tweet(): form = TweetForm() if form.validate_on_submit(): post = Post(content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash(f'Your tweet has been posted!', 'success') return redirect(url_for('home')) return render_template('create_tweet.html', title='New Tweet', form=form, legend='New Tweet')
def home(): form = TweetForm() if form.validate_on_submit(): post = Post(content=form.content.data, author=current_user) db.session.add(post) db.session.commit() print('got in home') flash(f'Your tweet has been posted!', 'success') return redirect(url_for('home')) page = request.args.get('page', 1, type=int) posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5) return render_template("home.html", posts=posts, form=form)
def update_tweet(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = TweetForm() if form.validate_on_submit(): post.content = form.content.data db.session.commit() flash('Your tweet has been updated!', 'success') return redirect(url_for('tweet', post_id=post.id)) elif request.method == 'GET': form.content.data = post.content return render_template('create_tweet.html', title='Update Tweet', form=form, legend='Update Tweet')