コード例 #1
0
 def mutate(self, info, **kwargs):
     user = User.query.filter_by(uuid=kwargs.get('author_uuid')).first()
     post = Post(title=kwargs.get('title'), body=kwargs.get('body'))
     if user is not None:
         post.author = user
     db.session.add(post)
     db.session.commit()
     return CreatePost(post=post)
コード例 #2
0
def add_post():
    if request.method == 'GET':
        boards = Boards.query.all()
        return render_template('front/front_post.html', boards=boards)
    else:
        form = Addpost_form(request.form)
        if form.validate():
            title = form.title.data
            context = form.context.data
            board_id = form.board_id.data
            board = Boards.query.filter_by(id=board_id).first()
            if not board:
                return xtjson.json_params_error(message=u'该板块不存在')
            post = Post(title=title, context=context)
            post.author = flask.g.front_user
            post.board = board
            if post.author.points >= contants.ADDPOST_POINTS:
                db.session.add(post)
                db.session.commit()
                return xtjson.json_result()
            else:
                return xtjson.json_params_error(message=u'您的论坛积分未达到10分不能发表帖子!')
        else:
            return xtjson.json_params_error(message=form.error_message())