def api_post_noso():
    current_app.logger.info("New Mobile Call - GET NOSO POST")
    allposts = Post.query.filter(Post.title.like("%noso%")).order_by(
        Post.date_posted.desc()).limit(250).all()
    posts_schema = PostSchema(many=True)
    result = posts_schema.dump(allposts)
    return jsonify(result.data)
示例#2
0
@posts.route("/post/<int:post_id>/delete", methods=['POST'])
@login_required
def delete_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    db.session.delete(post)
    db.session.commit()
    flash('Your post has been deleted!', 'success')
    return redirect(url_for('main.home'))


# REST api

# Init schema
post_schema = PostSchema(strict=True)
posts_schema = PostSchema(many=True, strict=True)


#Create a Post
@posts.route("/post/add/apiV1", methods=['POST'])
def add_posts():
    user = User.query.filter_by(
        username=request.authorization.username).first()
    if user and bcrypt.check_password_hash(user.password,
                                           request.authorization.password):
        api_post = Post(title=request.json['title'],
                        content=request.json['content'],
                        user_id=user.id)
        db.session.add(api_post)
        db.session.commit()
示例#3
0
 def get(self, title):
     post = Post.query.filter_by(title=title).first()
     result = PostSchema().dump(post)
     return jsonify(result)
示例#4
0
 def get(self):
     posts = db.session.query(Post).all()
     result = PostSchema(many=True).dump(posts)
     return jsonify(result)
def api_post_all():
    current_app.logger.info("New Mobile Call - GET ALL POST")
    allposts = Post.query.order_by(Post.date_posted.desc()).limit(250).all()
    posts_schema = PostSchema(many=True)
    result = posts_schema.dump(allposts)
    return jsonify(result.data)