Exemplo n.º 1
0
def article_create():
    form = ArticleCreateForm()
    form.category_id.choices = Category.choices()
    if request.method == 'POST' and form.validate():
        if not g.user.is_admin():
            flash(u'非管理员不能创建文章!')
            return redirect(url_for('index'))
        else:
            nowtime = datetime.datetime.now()
            article = Article(title=form.title.data,
                              body=form.body.data,
                              user_id=g.user.id,
                              category_id=form.category_id.data,
                              text=request.form.get('textformat'),
                              timestamp=nowtime,
                              tag=form.tag.data,
                              is_open=form.is_open.data)
            article.post_date = nowtime
            db.session.add(article)
            db.session.commit()
            flash(u'文章已创建!')
            Blog_info.new_article()
            return redirect(url_for('article_edit', id=article.id))
    return render_template('article_create.html',
                           title=u'创建文章',
                           form=form)
Exemplo n.º 2
0
def article_edit(id):
    form = ArticleEditForm()
    form.category_id.choices = Category.choices()
    article = Article.find_by_id(int(id))
    form.title.data = article.title
    form.body.data = article.body
    form.tag.data = article.tag
    form.category_id.data = article.category_id
    form.is_open.data = article.is_open
    form.id.data = id
    return render_template('article_edit.html',
                           title=u'编辑' + article.title,
                           form=form)
Exemplo n.º 3
0
def article_edit(id):
    form = ArticleEditForm()
    form.category_id.choices = Category.choices()
    article = Article.find_by_id(int(id))
    form.title.data = article.title
    form.body.data = article.body
    form.tag.data = article.tag
    form.category_id.data = article.category_id
    form.is_open.data = article.is_open
    form.id.data = id
    return render_template('article_edit.html',
                           title=u'编辑' + article.title,
                           form=form)
Exemplo n.º 4
0
def article_create():
    form = ArticleCreateForm()
    form.category_id.choices = Category.choices()
    if request.method == 'POST' and form.validate():
        if not g.user.is_admin():
            flash(u'非管理员不能创建文章!')
            return redirect(url_for('index'))
        else:
            nowtime = datetime.datetime.now()
            article = Article(title=form.title.data,
                              body=form.body.data,
                              user_id=g.user.id,
                              category_id=form.category_id.data,
                              text=request.form.get('textformat'),
                              timestamp=nowtime,
                              tag=form.tag.data,
                              is_open=form.is_open.data)
            article.post_date = nowtime
            db.session.add(article)
            db.session.commit()
            flash(u'文章已创建!')
            Blog_info.new_article()
            return redirect(url_for('article_edit', id=article.id))
    return render_template('article_create.html', title=u'创建文章', form=form)