def get_recommend_articles(category=None, limit=10): """ 返回推荐文章列表 :param category: 当前栏目,`None`或者`Category`实例 :param limit: 返回的个数,正整数,默认为10 """ _query = Article.query.public() if isinstance(category, Category): cate_ids = get_category_ids(category.longslug) _query = _query.filter(Article.category_id.in_(cate_ids)) return _query.filter_by(recommend=True).limit(int(limit)).all()
def get_thumbnail_articles(category=None, limit=10): """ 返回有缩略图的文章列表 :param category: 当前栏目,`None`或者`Category`实例 :param limit: 返回的个数,正整数,默认为10 """ _query = Article.query.public() if isinstance(category, Category): cate_ids = get_category_ids(category.longslug) _query = _query.filter(Article.category_id.in_(cate_ids)) return _query.filter(Article.thumbnail.isnot(None)).limit(int(limit)).all()
def get_latest_articles(category=None, limit=10): """ 返回最新文章列表 :param category: 当前栏目,`None`或者`Category`实例 :param limit: 返回的个数,正整数,默认为10 """ if isinstance(category, Category): cate_ids = get_category_ids(category.longslug) return Article.query.public().filter(Article.category_id.in_(cate_ids)) \ .limit(int(limit)).all() return Article.query.public().limit(int(limit)).all()
def get_thumbnail_articles(category=None, limit=10): """ 返回有缩略图的文章列表 :param category: 当前栏目,`None`或者`Category`实例 :param limit: 返回的个数,正整数,默认为10 """ _query = Article.query.public() if isinstance(category, Category): cate_ids = get_category_ids(category.longslug) _query = _query.filter(Article.category_id.in_(cate_ids)) return _query.filter(Article.thumbnail.isnot(None)).limit( int(limit)).all()
def get_articles_by_category(longslug='', limit=10, expand=True): """ 根据栏目路径返回文章列表 :param longslug: 栏目路径,字符串,不要以`/`结尾 :param limit: 返回的个数,整数 :param expand: 是否返回子栏目文章,`False`则只返回当前栏目的文章 """ _query = Article.query.public() category = Category.query.filter_by(longslug=longslug).first() if category: if expand: cate_ids = get_category_ids(longslug) _query = _query.filter(Article.category_id.in_(cate_ids)) else: _query = _query.filter_by(category_id=category.id) return _query.limit(int(limit)).all()
def get_articles_by_category(longslug, limit=10, showall=True): """ 根据栏目路径返回文章列表 :param longslug: 栏目路径,字符串,不要以`/`结尾 :param limit: 返回的个数,整数 :param showall: 是否返回子栏目文章,`False`则只返回当前栏目的文章 """ category = Category.query.filter_by(longslug=longslug).first() if category: if showall: cate_ids = get_category_ids(longslug) return Article.query.public() \ .filter(Article.category_id.in_(cate_ids)) \ .limit(int(limit)).all() else: return Article.query.public() \ .filter_by(category_id=category.id) \ .limit(int(limit)).all() return []