예제 #1
0
파일: blog.py 프로젝트: yashika/lyanna
async def topics(request: Request, ident: int = 1) -> Dict[str, Pagination]:
    start = (ident - 1) * PER_PAGE
    topics = await SpecialTopic.get_all()
    total = len(topics)
    topics = topics[start: start + PER_PAGE]
    paginatior = Pagination(ident, PER_PAGE, total, topics)
    return {'paginatior': paginatior}
예제 #2
0
async def _get_post_context(page=1):
    page = int(page)
    start = (page - 1) * PER_PAGE
    posts = await Post.get_all()
    total = len(posts)
    posts = posts[start: start + PER_PAGE]
    paginatior = Pagination(page, PER_PAGE, total, posts)
    return {'paginatior': paginatior, 'total': total, 'msg': '', 'page': page}
예제 #3
0
async def _posts(request, page=1):
    start = (page - 1) * PER_PAGE
    posts = await Post.get_all(with_page=False)
    total = len(posts)
    posts = posts[start:start + PER_PAGE]
    paginatior = Pagination(page, PER_PAGE, total, posts)
    profile = await Profile.get()
    return {'paginatior': paginatior, 'profile': profile}
예제 #4
0
async def _topics(request: Request,
                  ident: Union[str, int] = 1) -> Dict[str, Pagination]:
    try:
        ident = int(ident)
    except ValueError:
        abort(404)
    start = (ident - 1) * PER_PAGE  # type: ignore
    topics = await SpecialTopic.get_all()
    total = len(topics)
    topics = topics[start:start + PER_PAGE]
    paginatior = Pagination(ident, PER_PAGE, total, topics)  # type: ignore
    return {'paginatior': paginatior}
예제 #5
0
async def index(request: Request, page=1):
    start = (page - 1) * config.PER_PAGE
    posts = await Post.get_all(with_page=False)
    total = len(posts)
    posts = posts[start:start + config.PER_PAGE]
    post_objs = [await Post(**p).to_async_dict(**p) for p in posts]
    paginatior = Pagination(page, config.PER_PAGE, total, post_objs)
    json = {'paginatior': paginatior}

    for partial in config.partials:
        partial = config.AttrDict(partial)
        if partial.name == 'tagcloud':
            tags = await _tags()
            random.shuffle(tags)
            json.update({'tags': tags})

    return json
예제 #6
0
파일: blog.py 프로젝트: yashika/lyanna
async def _posts(request: Request, page: int = 1):
    start = (page - 1) * PER_PAGE
    posts = await Post.get_all(with_page=False)
    total = len(posts)
    posts = posts[start: start + PER_PAGE]
    paginatior = Pagination(page, PER_PAGE, total, posts)
    json: Dict[
        str, Union[List[Tuple[int, Post]], List[AttrDict],
                   List[Tuple[Tag, int]], Pagination]] = {'paginatior': paginatior}

    for partial in partials:
        partial = AttrDict(partial)
        if partial.name == 'most_viewed':
            json.update({
                'most_viewed_posts': await get_most_viewed_posts(
                    partial.count)
            })
        elif partial.name == 'latest_comments':
            comments = await get_latest_comments(partial.count)
            latest_comments = []
            for c in comments:
                user = await c.user
                post = await Post.cache(c.target_id)
                user = AttrDict({
                    'name': user.username,
                    'link': user.link,
                    'avatar': user.picture,
                })
                post = AttrDict({
                    'title': post.title if post else '[已删除]',
                })
                dct = {
                    'user': user,
                    'post': post,
                    'content': await c.content,
                    'date': c.created_at.strftime('%Y-%m-%d')
                }
                latest_comments.append(AttrDict(dct))
            json.update({'latest_comments': latest_comments})
        elif partial.name == 'tagcloud':
            tags = await _tags()
            random.shuffle(tags)
            json.update({'tags': tags})
    return json