def edit_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(f'Your post has been updated !', 'success') return redirect(url_for('post', post_id=post.id)) if request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Edit Post', legend='Edit Post', form=form, is_post=True)
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() return redirect(url_for("home")) return render_template("create_post.html", title="New post", form=form)
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 is submitted','success') return redirect(url_for('hello')) return render_template('create_post.html',title='New Post',form=form,legend='Update 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('Your post has been created!', 'success') return redirect(url_for('home')) return render('new_post.html', title='New Post', form=form)
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 has created", 'success') return redirect(url_for('home')) return render_template("create_post.html",title='New Post',form=form, legend='New Post')
def create_post(): form = PostForm() if form.validate_on_submit(): new_post = Post(title=form.title.data, content=form.content.data, date_updated=None, author=current_user) db.session.add(new_post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('index')) return render_template('create_post.html', page_title='New Post', form=form, img_file_src=get_img_src())
def create_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_id=current_user.id) db.session.add(post) db.session.commit() flash("Post Created Successfully", "success") return redirect(url_for("home")) return render_template("create_post.html", form=form)
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('Post Created successfully', 'success') return redirect('home') return render_template('new.html', form=form)
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=post.title,post=post,form=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.title.data db.session.commit() flash("Post 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('post_update.html', title='Update Post', form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): # here we are creating the post 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')) # legend is used to pass title of the form same in update post function 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(message='Your post has been created', category='success') # 'success' is boostrap return redirect(url_for('home')) return render_template("create_post.html", title="New Post", form=form, os=os, legend="New Post")
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: # http response for forbidden route, will customise later 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 update_post(post_id): form = PostForm() user_post = Post.query.get_or_404(post_id) if user_post.author != current_user: abort(403) if request.method == 'GET': form.title.data = user_post.title form.content.data = user_post.content if form.validate_on_submit(): user_post.title = form.title.data user_post.content = form.content.data user_post.date_updated = datetime.now() db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('index')) return render_template('update_post.html', page_title='Update Post', form=form, img_file_src=get_img_src())
def new_post(): if not current_user.is_authenticated: flash(f'Please Login First', 'info') return redirect('login') 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('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post', is_post=True)
def update_post(post_id): post = Post.query.get_or_404(post_id) # so that the user who wrote the post will be able to update it if post.author != current_user: # 403 is used for forbidden access abort(403) form = PostForm() if form.validate_on_submit(): # to populate the update form with existing post data post.title = form.title.data post.content = form.content.data # we dont need to do add as these changes are already in the database we just need to update it 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')