Пример #1
0
 def _get_paginator(self, page):
     category_id = self.kwargs['category_id']
     per_page = int(self.request.GET.get('per_page', 7))
     self.paginator = DeerUPaginator(
         filter_article_by_category(category_id).order_by('-id'), per_page,
         page)
     return self.paginator
Пример #2
0
def article_list_view(request):
    filter_type = request.GET.get('filter_type', 'article')
    per_page = int(request.GET.get('per_page', 7))
    page = int(request.GET.get('page', 1))

    if page < 1:
        return JsonFailResponse({'code': 404, 'msg': '404'})

    result = {}

    if filter_type == 'article':
        paginator = DeerUPaginator(filter_article_order_by_id(), per_page,
                                   page)

    elif filter_type == 'category':
        category_id = request.GET.get('category_id')
        if not category_id:
            return JsonFailResponse({'msg': '缺少必要参数category_id'})
        paginator = DeerUPaginator(
            filter_article_by_category(category_id).order_by('-id'), per_page,
            page)

        # category = get_category_by_id(category_id)
        # result = detail_category_dict(category)

    elif filter_type == 'tag':
        tag_id = request.GET.get('tag_id')
        if not tag_id:
            return JsonFailResponse({'msg': '缺少必要参数tag_id'})
        paginator = DeerUPaginator(
            filter_article_by_tag(tag_id).order_by('-id'), per_page, page)

        # tag = get_tag_by_id(tag_id)
        # result = detail_tag_dict(tag)
    else:
        return JsonFailResponse({'msg': '参数filter_type错误'})

    if page > paginator.end_index:
        return JsonFailResponse({'code': 404, 'msg': '404'})

    article_list = paginator.page(page).object_list
    result['article_list'] = []
    result['paginator'] = {
        'end_index': paginator.end_index,
        'current_page_num': page
    }

    for article in article_list:
        result['article_list'].append({
            'article':
            article_to_preview_dict(article),
            'article_meta':
            model_to_dict(article.meta_data()),
            'category': [model_to_dict(c) for c in article.category()],
            'tags': [model_to_dict(t) for t in article.tags()],
        })

    return JsonSuccessResponse(result)
Пример #3
0
 def _get_paginator(self, page):
     per_page = int(self.request.GET.get('per_page', 7))
     self.paginator = DeerUPaginator(all_article_order_by_id(), per_page,
                                     page)
     return self.paginator
Пример #4
0
def get_article_list_and_paginator(page, per_page):
    paginator = DeerUPaginator(all_article_order_by_id(), per_page, page)

    article_list = paginator.page(page).object_list
    return article_list, paginator
Пример #5
0
def get_article_list_and_paginator_by_tag(tag_id, page, per_page):
    paginator = DeerUPaginator(filter_article_by_tag(tag_id), per_page, page)

    article_list = paginator.page(page).object_list
    return article_list, paginator
Пример #6
0
 def _get_paginator(self, page):
     category_id = self.kwargs['category_id']
     self.paginator = DeerUPaginator(filter_article_by_category(category_id).order_by('-id'), 7, page)
     return self.paginator
Пример #7
0
 def _get_paginator(self, page):
     self.paginator = DeerUPaginator(filter_article_order_by_id(), 7, page)
     return self.paginator
Пример #8
0
 def _get_paginator(self, page):
     tag_id = self.kwargs['tag_id']
     self.paginator = DeerUPaginator(filter_article_by_tag(tag_id).order_by('-id'), 7, page)
     return self.paginator