コード例 #1
0
 def get(self):
     try:
         posts = Post.objects().to_json()
         return Response(posts, mimetype="application/json", status=200)
     except DoesNotExist:
         raise NotExistsError
     except Exception:
         raise InternalServerError
コード例 #2
0
    def get(self):
        try:
            user_id = get_jwt_identity()
            user = User.objects.get(id=user_id)

            ids = user.following
            ids.append(user)

            posts = Post.objects(author__in=ids)
            posts = [convert_post(ob) for ob in posts]
            posts.sort(key=operator.itemgetter('created_at'), reverse=True)

            return Response(JSONEncoder().encode(posts),
                            mimetype="application/json",
                            status=200)
        except DoesNotExist:
            raise DocumentMissing
        except Exception as e:
            raise InternalServerError
コード例 #3
0
ファイル: post.py プロジェクト: mdkhalake/api
 def get(self):
     posts = Post.objects().to_json()
     return Response(posts, mimetype="application/json", status=200)