コード例 #1
0
def category(category_id):

    # get category information
    category_info = (Categories.get(Categories.category_id == category_id))

    # get posts list.
    article_list = (BasketArticleList.select().join(Authors, on=(Authors.author_id == BasketArticleList.author))
                    .where(BasketArticleList.category == category_info.category_id,
                           BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)
                    .order_by(-BasketArticleList.updated_at).limit(10))

    for post in article_list:
        post.category = category_info

    # get page number
    page_num = math.ceil(len(BasketArticleList.filter(
        BasketArticleList.category == category_info.category_id,
        BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)) / 10)

    # get tags
    tags = Tags.select()

    # get popular articles.
    popular_articles = (BasketArticleList.select().join(Authors, on=(Authors.author_id == BasketArticleList.author))
                        .where(BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)
                        .order_by(-BasketArticleList.updated_at).limit(5))

    return {
        'article_list': basket_article_list_serializer.dump(article_list, many=True).data,
        'current_page': 1,
        'max_page': page_num,
        'category': category_info,
        'tags': tags,
        'popular_posts': popular_articles,
    }
コード例 #2
0
def posts(page):

    # if get the first page of the posts,
    # redirect to the index page.
    if page == 1:
        redirect('/')

    # get current page posts.
    article_list = (BasketArticleList.select().join(Authors, on=(Authors.author_id == BasketArticleList.author))
                    .join(Categories, on=(Categories.category_id == BasketArticleList.category))
                    .where(BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)
                    .order_by(-BasketArticleList.updated_at).paginate(page, 10))

    # get page number
    page_num = math.ceil(len(BasketArticleList.filter(
        BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)) / 10)

    # get tags
    tags = Tags.select()

    # get popular articles.
    popular_articles = (BasketArticleList.select().join(Authors, on=(Authors.author_id == BasketArticleList.author))
                        .where(BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value)
                        .order_by(-BasketArticleList.updated_at).limit(5))

    return {
        'article_list': basket_article_list_serializer.dump(article_list, many=True).data,
        'current_page': page,
        'max_page': page_num,
        'tags': tags,
        'popular_posts': popular_articles
    }
コード例 #3
0
def author(author_id, page):
    if page == 1:
        redirect('/author/' + quote(author_id))
    # get author information
    author_info = (Authors.get(Authors.author_id == author_id))

    # get posts list.
    article_list = (BasketArticleList.select().join(
        Categories,
        on=(Categories.category_id == BasketArticleList.category)).where(
            BasketArticleList.author == author_info.author_id,
            BasketArticleList.show_status ==
            ShowStatusEnum.PUBLIC_POST.value).order_by(
                BasketArticleList.updated_at).paginate(page, 10))

    for post in article_list:
        post.author = author_info

    # get page number
    page_num = math.ceil(
        len(
            BasketArticleList.filter(
                BasketArticleList.author == author_id,
                BasketArticleList.show_status
                == ShowStatusEnum.PUBLIC_POST.value)) / 10)

    # get tags
    tags = Tags.select()

    # get popular articles.
    popular_articles = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).where(
            BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value).
                        order_by(-BasketArticleList.updated_at).limit(5))

    return {
        'article_list':
        basket_article_list_serializer.dump(article_list, many=True).data,
        'current_page':
        page,
        'max_page':
        page_num,
        'author':
        author_info,
        'tags':
        tags,
        'popular_posts':
        popular_articles,
    }
コード例 #4
0
def category(year, page):
    if page == 1:
        redirect('/archive/' + str(year))

    # get posts list.
    article_list = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).join(
            Categories,
            on=(Categories.category_id == BasketArticleList.category)).where(
                BasketArticleList.updated_at.year == year,
                BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.
                value).order_by(-BasketArticleList.updated_at).paginate(
                    page, 10))

    # get page number
    page_num = math.ceil(
        len(
            BasketArticleList.filter(
                BasketArticleList.updated_at.year == year,
                BasketArticleList.show_status
                == ShowStatusEnum.PUBLIC_POST.value)) / 10)

    # get tags
    tags = Tags.select()

    # get popular articles.
    popular_articles = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).where(
            BasketArticleList.show_status == ShowStatusEnum.PUBLIC_POST.value).
                        order_by(-BasketArticleList.updated_at).limit(5))

    return {
        'article_list':
        basket_article_list_serializer.dump(article_list, many=True).data,
        'current_page':
        page,
        'max_page':
        page_num,
        'tags':
        tags,
        'popular_post':
        popular_articles,
        'year':
        year
    }