コード例 #1
0
def create():
    if request.method == 'POST':
        form = PostForm(request.form)
        if form.validate():
            post = form.save_post(Post(author=g.user))
            db.session.add(post)
            db.session.commit()
            flash('Post "%s" created successfully.' % post.title, 'success')
            return redirect(url_for('posts.detail', slug=post.slug))
    else:
        form = PostForm()
    return render_template('posts/create.html', form=form)
コード例 #2
0
def edit(slug):
    post = get_post_or_404(slug, author=None)
    #post = Post.query.filter(Post.slug == slug).first_or_404()
    if request.method == 'POST':
        form = PostForm(request.form, obj=post)
        if form.validate():
            post = form.save_post(post)
            db.session.add(post)
            db.session.commit()
            return redirect(url_for('posts.detail', slug=post.slug))
    else:
        form = PostForm(obj=post)
    return render_template('posts/edit.html', post=post, form=form)
コード例 #3
0
ファイル: views.py プロジェクト: KarolJanik/sky-twitter
def add_post():
    form = PostForm(request.form)
    if form.validate():
        post = Post(bleach.clean(form.content.data), current_user.id, datetime.datetime.utcnow())
        words = form.content.data.split()
        for tag in Tag.parse_tags(words):
            db_session.add(tag)
            post.tags.append(tag)
        db_session.add(post)
        db_session.commit()
        flash("Successful!")
    else:
        flash("Something went wrong. Make sure that your tweet's length is less than 140 characters", 'error')
    return redirect(url_for('main.hello'))