コード例 #1
0
ファイル: routes.py プロジェクト: directx8/BrightDream
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()

    # If the form is filled in correctly update the title and content
    # and commit the new data to the database
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        post.percentage = form.percentage.data
        post.price = form.price.data
        post.place = form.place.data
        post.turnover = form.turnover.data
        post.field = form.field.data
        db.session.commit()
        flash("Your post has been updated!", "success")
        return redirect(url_for('company_list', post_id=post.id))
    elif request.method == "GET":
        form.title.data = post.title
        form.content.data = post.content
        form.percentage.data = post.percentage
        form.price.data = post.price
        form.place.data = post.place
        form.turnover.data = post.turnover
        form.field.data = post.field
    return render_template("create_post.html",
                           title="Update Post",
                           form=form,
                           legend="Update Post")
コード例 #2
0
ファイル: routes.py プロジェクト: directx8/BrightDream
def new_post():
    form = PostForm()

    # If the form is filled in correctly populate the post data
    # and commit the new data to the database
    if form.validate_on_submit():
        post = Post(
            title=form.title.data,
            content=form.content.data,
            author=current_user,
            percentage=form.percentage.data,
            price=form.price.data,
            place=form.place.data,
            turnover=form.turnover.data,
            field=form.field.data,
        )
        db.session.add(post)
        db.session.commit()
        flash("Post has been created!", "success")
        return redirect(url_for('company_list'))
    return render_template("create_post.html",
                           title="Add Post",
                           form=form,
                           legend="New Post")