Esempio n. 1
0
File: views.py Progetto: andyzt/tceh
def view():
    from models import User, Post

    if request.method == 'POST':

        form = AddPostForm(request.form)
        if form.validate():

            post = Post(title=form.data['title'], content=form.data['content'], user=current_user)
            post.is_visible = True

            print("{} is creating a new {}'th post!".format(
               post.user.username, len(post.user.posts.all()) + 1))
            print post.id

            db.session.add(post)
            db.session.commit()
            flash('Post created!')

        else:
            flash('Form is not valid! Post was not created.')

    else:
        form = AddPostForm()

    posts = Post.query.filter_by(is_visible=True).all()
    return render_template('home.html', form=form, posts=posts)
Esempio n. 2
0
def add_post():
    form = AddPostForm(request.form)
    if request.method == 'POST' and form.validate():
        post = Post(form.title.data, form.filename_content.data,
                    datetime.now(), form.category.data, form.author.data)
        db.session.add(post)
        db.session.commit()
        flash('Post added', 'info')
        return redirect(url_for('add_post'))
    return render_template('_add.html',
                           form=form,
                           rows=Post.query.all(),
                           target_model="Post",
                           fields=Post.__mapper__.c.keys(),
                           action="addpost")
Esempio n. 3
0
def add_post():
    form = AddPostForm(request.form)
    if request.method == "POST" and form.validate():
        post = Post(form.title.data, form.filename_content.data, datetime.now(), form.category.data, form.author.data)
        db.session.add(post)
        db.session.commit()
        flash("Post added", "info")
        return redirect(url_for("add_post"))
    return render_template(
        "_add.html",
        form=form,
        rows=Post.query.all(),
        target_model="Post",
        fields=Post.__mapper__.c.keys(),
        action="addpost",
    )