msg.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:msg 作者: lily-mayfield 项目源码 文件源码
def get(self):
        """Get a range of messages using a "limit"
        and an "offset."

        Returns:
            list: list of dictionaries describing
                messages, if successful.
            None: If aborted.

        """

        json_data = get_valid_json(self.SCHEMA_GET)
        offset = int(json_data['offset'])
        limit = int(json_data['limit'])

        # Just make sure not requesting too many at once!
        if limit > config.LIMITS_MESSAGES_GET_LIMIT:
            message = ("You may only request %d messages at once."
                       % config.LIMITS_MESSAGES_GET_LIMIT)
            flask_restful.abort(400, message=message)

        # Now we're sure we have the right data to
        # make a query, actually do that query and
        # return said data or 404 if nothing matches.
        query = db.session.query(models.Message)
        results = query.limit(limit).offset(offset).all()

        if results == []:
            message = ("No messages found at offset %d limit %d"
                       % (offset, limit))
            flask_restful.abort(404, message=message)
        else:
            return [r.to_dict() for r in results]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号