Beispiel #1
0
def addpost():
    form = PostForm(request.form)
    if request.method == 'POST' and form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        tags = normalize_tags(form.tags.data)
        entry = Post(title=title, content=content)
        entry.tags = tags
        try:
            entry.store_to_db()
            flash(u'文章存入成功')
        except:
            flash(u'文章存入失败,请与管理员联系')

        return redirect(url_for('admin.index'))
            
    return render_template('admin/addpost.html', form=form)
Beispiel #2
0
def edit(id):
    entry = Post.query.filter_by(id=id).first()
    if not entry:
        abort(404)

    taglist = []
    for tag in entry.tags:
        taglist.append(tag.name)

    form = PostForm(title=entry.title, content=entry.content, tags=','.join(taglist))
    if request.method == 'POST' and form.validate_on_submit():
        Post.query.filter_by(id=id).update({
            Post.title: request.form['title'],
            Post.content: request.form['content'],
            Post.tags: request.form['tags']})
        db.session.commit()
        return redirect(url_for('admin.mnpost'))

    return render_template('admin/edit.html', form=form)