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

    # get six top posts.
    six_top_posts = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).join(
            Categories,
            on=(Categories.category_id == BasketArticleList.category)).where(
                BasketArticleList.is_top == 1).order_by(
                    BasketArticleList.post_date).limit(6))

    # get current page posts.
    article_list = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).join(
            Categories,
            on=(Categories.category_id == BasketArticleList.category
                )).order_by(BasketArticleList.post_date).paginate(page, 10))

    # get page number
    page_num = int(
        len(BasketArticleList.select(BasketArticleList.post_id)) / 10)

    return {
        'article_list': post_serializer.dump(article_list, many=True).data,
        'six_top_posts': post_serializer.dump(six_top_posts, many=True).data,
        'current_page': page,
        'max_page': page_num
    }
Example #2
0
def category(category_name, page):
    if page == 1:
        redirect('/category/' + category_name)
    # get category information
    category_info = (Categories.get(Categories.category_name == category_name))

    # get posts list.
    article_list = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).where(
            BasketArticleList.category == category_info.category_id).order_by(
                BasketArticleList.post_date).paginate(page, 10))

    for post in article_list:
        post.category = category_info

    # get page number
    page_num = int(
        len(BasketArticleList.select(BasketArticleList.post_id)) / 10)
    #
    return {
        'article_list': post_serializer.dump(article_list, many=True).data,
        'current_page': page,
        'max_page': page_num,
        'category': category_info
    }
Example #3
0
def index():
    # get six top posts.
    six_top_posts = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).join(
            Categories,
            on=(Categories.category_id == BasketArticleList.category)).where(
                BasketArticleList.is_top == 1).order_by(
                    BasketArticleList.post_date).limit(6))

    # get posts list.
    article_list = (BasketArticleList.select().join(
        Authors, on=(Authors.author_id == BasketArticleList.author)).join(
            Categories,
            on=(Categories.category_id == BasketArticleList.category
                )).order_by(BasketArticleList.post_date).limit(10))

    # get page number
    page_num = int(
        len(BasketArticleList.select(BasketArticleList.post_id)) / 10)

    return {
        'article_list': post_serializer.dump(article_list, many=True).data,
        'six_top_posts': post_serializer.dump(six_top_posts, many=True).data,
        'current_page': 1,
        'max_page': page_num
    }
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,
    }
Example #5
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
    }
Example #6
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,
    }
Example #7
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
    }
Example #8
0
def author(author_name):

    # get author information
    author_info = (Authors.get(Authors.author_name == author_name))

    # get posts list.
    article_list = (BasketArticleList.select()
                    .join(Categories, on=(Categories.category_id == BasketArticleList.category))
                    .where(BasketArticleList.author == author_info.author_id)
                    .order_by(BasketArticleList.post_date).limit(10))

    for post in article_list:
        post.author = author_info

    # get page number
    page_num = int(len(BasketArticleList.select(BasketArticleList.post_id)) / 10)

    return {
        'article_list': post_serializer.dump(article_list, many=True).data,
        'current_page': 1,
        'max_page': page_num,
        'author': author_info
    }