예제 #1
0
def new_post():
    form = PostForm()
    mobans = Moban.query.all()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        obperson = form.obperson.data
        category = Category.query.get(form.category.data)
        author = current_user.username
        post = Post(title=title, body=body, category=category,obperson=obperson,author=author)
        send_post = Post.query.filter_by(reviewed=False).count()
        send_post = send_post + 12
        db.session.add(post)
        db.session.commit()
        if current_user.is_admin:
            flash('添加成功', 'success')
            return redirect(url_for('blog.show_post', post_id=post.id))
        else:
            flash('您的文章正在审核', 'info')
            msg = '有新的文章请您审核\n' \
                  'http://172.18.5.118:5000/post/{0}'.format(send_post)
            wechat = Wechat()
            wechat.Send_Message(msg)
            return redirect(url_for('blog.index'))
    return render_template('admin/new_post.html', form=form,mobans=mobans)
예제 #2
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        category = Category.query.get(form.category.data)
        tags = []
        for tag in form.tags.data:
            tags.append(Tag.query.get(tag))
        # tags = Tag.query.get(form.tags.data)
        published = form.published.data
        pinned = form.pinned.data
        post = Post(title=title,
                    body=body,
                    tags=tags,
                    category=category,
                    published=published,
                    pinned=pinned)
        # same with:
        # category_id = form.category.data
        # post = Post(title=title, body=body, category_id=category_id)
        db.session.add(post)
        db.session.commit()
        flash('Post created.', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #3
0
def edit_moban(moban_id):
    form = PostForm()
    mobans = Moban.query.all()
    moban = Moban.query.get_or_404(moban_id)
    if form.validate_on_submit():
        # moban = Moban.query.get_or_404(moban_id)
        body = form.body.data
        title = form.title.data
        obperson = form.obperson.data
        category = Category.query.get(form.category.data)
        author = current_user.username
        post = Post(title=title, body=body, category=category, obperson=obperson, author=author)
        send_post = Post.query.filter_by(reviewed=False).order_by(Post.timestamp.desc()).count() + 2
        print(send_post)
        db.session.add(post)
        db.session.commit()
        if current_user.is_admin:
            flash('添加成功', 'success')
            return redirect(url_for('blog.show_post', post_id=post.id))
        else:
            flash('您的文章正在审核', 'info')
            url = 'http://172.18.5.118:5000/post/{0}'.format(send_post)
            msg = '有新的文章请您审核\n' + url
                  # 'http://172.18.5.118:5000/post/{0}'.format(send_post)
            if url:
                return redirect(url_for('auth.login',username="******",password="******"))
            wechat = Wechat()
            wechat.Send_Message(msg)
            return redirect(url_for('blog.index'))
    form.body.data = moban.body
    return render_template('admin/new_post.html', form=form,mobans=mobans)
예제 #4
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    body=form.body.data,
                    category=Category.query.get(form.category.data))
        db.session.add(post)
        db.session.commit()
        flash('Post created.', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #5
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        category = Category.query.get(form.category.data)
        body = form.body.data
        post = Post(title=title, body=body, category=category)
        db.session.add(post)
        db.session.commit()
        flash('文章创建成功', '成功')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #6
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        # category是绑定的category的id
        category_id = form.category.data
        post = Post(title=title, body=body, category_id=category_id)
        db.session.add(post)
        db.session.commit()
        flash('新建文章成功', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #7
0
def edit_post(post_id):
    form = PostForm()
    post = Article.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        db.session.commit()
        flash('Post updated.', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
예제 #8
0
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category = Category.query.get(form.category.data)
        db.session.comment()
        flash('文章已被更新', '成功')
        return redirect(url_for('blog.show_post', post_id=post.id))
    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
예제 #9
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        logger.debug(form.data)
        # 创建新文章
        post = Post(
            title=form.title.data,
            body=form.body.data,
            category_id=form.category.data,
        )
        db.session.add(post)
        db.session.commit()
        flash('文章发表成功!', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #10
0
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.slug = slugify(post.title, max_len=240)
        post.body = form.body.data
        post.category = Category.query.get(form.category.data)
        db.session.commit()
        flash('Post updated.', 'success')
        return redirect(url_for('blog.show_post', slug=post.slug))
    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
예제 #11
0
파일: admin.py 프로젝트: TyouSF/FlaskWebAC
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        category = Category.query.get(form.category.data)
        post = Post(title=title, body=body, category=category)
        # same with:
        # category_id = form.category.data
        # post = Post(title=title, body=body, category_id=category_id)
        db.session.add(post)
        db.session.commit()
        flash('Post created. / 文章已经成功创建', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #12
0
파일: admin.py 프로젝트: MaXianSeng/flask
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category = Category.query.get(
            form.category.data)  #特别注意!,表单的分类字段是分类记录的id值
        db.session.commit()
        flash('Edit post success!', 'success')
        return redirect(url_for('blog.show_post', post_id=post_id))
    form.title.data = post.title
    form.category.data = post.category_id  #特别注意!
    form.body.data = post.body
    return render_template('admin/edit_post.html', form=form)
예제 #13
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        category = Category.query.get(form.category.data)
        post = Post(title=title,
                    body=body,
                    slug=slugify(title, max_len=240),
                    category=category)

        db.session.add(post)
        db.session.commit()
        flash('Post created.', 'success')
        return redirect(url_for('blog.show_post', slug=post.slug))
    return render_template('admin/new_post.html', form=form)
예제 #14
0
파일: admin.py 프로젝트: meizhaohui/bluelog
def edit_post(post_id):
    """编辑文章"""
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category = Category.query.get(form.category.data)
        post.timestamp = datetime.datetime.utcnow()
        db.session.add(post)
        db.session.commit()
        flash('Post Updated.', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
예제 #15
0
def new_post():
    """创建新文章界面路由函数

    Returns:
        创建新文章界面
    """
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        category = Category.query.get(form.category.data)
        post = Post(title=title, body=body, category=category)
        db.session.add(post)
        db.session.commit()
        flash('Post Created', 'Success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    return render_template('admin/new_post.html', form=form)
예제 #16
0
def edit_post(post_id):
    '''编辑博客的条目'''
    post = Post.query.get_or_404(post_id)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category.name = form.category.default
        return redirect(url_for('blog.show_post'))

    form.title.data = post.title
    form.body.data = post.body
    form.category.default = post.category.name
    return render_template(
        'admin/edit_post.html',
        form=form,
    )
예제 #17
0
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.body = form.body.data
        post.category = Category.query.get(form.category.data)
        tags = []
        for tag in form.tags.data:
            tags.append(Tag.query.get(tag))
        post.published = form.published.data
        post.pinned = form.pinned.data
        db.session.commit()
        flash('Post updated.', 'success')
        return redirect(url_for('blog.show_post', post_id=post.id))
    form.title.data = post.title
    form.body.data = post.body
    form.category.data = post.category_id
    return render_template('admin/edit_post.html', form=form)
예제 #18
0
def edit_post(post_id):
    form = PostForm()
    post = Post.query.get_or_404(post_id)
    if form.validate_on_submit():
        print(form.data)
        title = form.title.data
        category = Category.query.get(form.category.data)
        body = form.body.data
        post.title = title
        post.category = category
        post.body = body
        db.session.add(post)
        db.session.commit()
        flash('修改文章成功', 'success')
        return redirect(url_for('blog.show_post', post_id=post_id))
    form.title.data = post.title
    form.category.date = post.category.id
    form.body.data = post.body
    return render_template('admin/edit_post.html', form=form, post_id=post_id)
예제 #19
0
def new_post():
    form = PostForm()
    return render_template('admin/new_post.html', form=form)
예제 #20
0
def edit_post(post_id):
    form = PostForm()
    return render_template('admin/edit_post.html', form=form)