Esempio n. 1
0
def addArticle():
    form = request.form
    # 计算字数  就是计算字符串的长度
    numbers = len(form['content'])
    if request.method == 'POST':
        with db.auto_commit():
            article = Article()
            article.set_attrs(form)
            article.numbers = numbers
            db.session.add(article)
        return jsonify({'code': 200, 'message': '写入文章成功'})
Esempio n. 2
0
def edit():
    form = EditForm(request.form)
    uid = current_user.id
    user = User.query.filter_by(id=uid).first()
    form.author.data = user.nickname
    if request.method == 'POST' and form.validate():
        article = Article()
        with db.auto_commit():
            article.set_attrs(form.data)
            db.session.add(article)
            db.session.commit()

    return render_template('edit.html', form=form)
Esempio n. 3
0
def addArticle():
    form = request.form
    # 计算字数  就是计算字符串的长度
    numbers = len(form['content'])
    if request.method == 'POST':
        with db.auto_commit():
            field = 0
            if len(form['project_name']) > 0:
                field = 1
            # 获取当前年份
            year = datetime.now().year
            article = Article()
            article.set_attrs(form)
            article.numbers = numbers
            article.year = year
            article.field = field
            db.session.add(article)
        return jsonify({'code': 200, 'message': '写入文章成功'})