<commit_before># -*- coding: utf-8 -*-
from flask import Blueprint, render_template, redirect, url_for, flash
from flask.ext.login import login_required, current_user
from autoposter.user.models import Post
from .forms import NewPostForm

blueprint = Blueprint("user", __name__, url_prefix='/users',
                      static_folder="../static")


@blueprint.route("/posts")
@login_required
def posts():
    return render_template("users/posts.html", posts=current_user.posts)


@blueprint.route("/posts/add", methods=('GET', 'POST'))
@login_required
def add_post():
    new_post = Post()
    form = NewPostForm(obj=new_post)

    if form.validate_on_submit():

        form.populate_obj(new_post)

        new_post.save()

        current_user.posts.append(new_post)
        current_user.save()

        return redirect(url_for('user.posts'))

    return render_template("users/newpost.html", form=form)


@blueprint.route("/posts/edit/<id>", methods=('GET', 'POST'))
@login_required
def edit_post(id):
    post = Post.query.get(id)

    form = NewPostForm(obj=post)

    if form.validate_on_submit():

        form.populate_obj(post)

        post.save()

        flash("{} saved successfully!".format(post.title))

        return redirect(url_for('user.posts'))

    return render_template("users/newpost.html", form=form)<commit_msg>add_post now only creates Post after form submit<commit_after># -*- coding: utf-8 -*-
from flask import Blueprint, render_template, redirect, url_for, flash
from flask.ext.login import login_required, current_user
from autoposter.user.models import Post
from .forms import NewPostForm

blueprint = Blueprint("user", __name__, url_prefix='/users',
                      static_folder="../static")


@blueprint.route("/posts")
@login_required
def posts():
    return render_template("users/posts.html", posts=current_user.posts)


@blueprint.route("/posts/add", methods=('GET', 'POST'))
@login_required
def add_post():
    form = NewPostForm()

    if form.validate_on_submit():
        new_post = Post()
        form.populate_obj(new_post)
        current_user.posts.append(new_post)

        new_post.save()
        current_user.save()

        return redirect(url_for('user.posts'))

    return render_template("users/newpost.html", form=form)


@blueprint.route("/posts/edit/<id>", methods=('GET', 'POST'))
@login_required
def edit_post(id):
    post = Post.query.get(id)

    form = NewPostForm(obj=post)

    if form.validate_on_submit():

        form.populate_obj(post)

        post.save()

        flash("{} saved successfully!".format(post.title))

        return redirect(url_for('user.posts'))

    return render_template("users/newpost.html", form=form)
{'fraction_non_alphanumeric': 0.13937153419593346, 'fraction_numerical': 0.0007393715341959334, 'mean_word_length': 3.7473684210526317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7426520', 'n_tokens_mistral': 856, 'n_tokens_neox': 818, 'n_words': 164}