def add(): u = current_user() form = request.json form['user_id'] = u.id form['username'] = u.username c = Comment.new(form) c.save() return jsonify(c.json())
def add(form): result = dict(success=False) res = comment_schema.load(form) if res.errors == {}: result['success'] = True c = Comment.new(res.data) user = c.user data = dict(comment=comment_schema.dump(c).data, user=user_schema.dump(user).data) result['data'] = data create_notify(c.post, user) subscribe_comment(c, user) result['message'] = res.errors return result