예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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')
예제 #4
0
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)
예제 #5
0
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')
예제 #6
0
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())
예제 #7
0
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")
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
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')
예제 #11
0
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)
예제 #12
0
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')
예제 #13
0
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")
예제 #14
0
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')
예제 #15
0
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())
예제 #16
0
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)
예제 #17
0
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')