Пример #1
0
def category_view(request, category_slug, page=1):
    category = get_object_or_404(Category, slug=category_slug)
    news = News.objects.filter(category=category)
    pager = get_page(news, 5, page)
    categories = Category.objects.all()
    return render_to_response('html/news.html', {"news": pager,
                                                  "categories": categories,
                                                  "category": category})
Пример #2
0
def ajax_page(request, page):
    if request.method == 'GET':
        mimetype = 'application/json'
        news = News.objects.all()
        pager = get_page(news, 5, page)
        slug_next = "none"
        if pager.has_next():
            slug_next = reverse('news:index', kwargs={"page": pager.next_page_number()})
        arr = []
        for new in pager:
            arr.append(NewsWrapper(new, page=pager.number, slug_next=slug_next))
        return HttpResponse(to_json(arr), mimetype)
Пример #3
0
def ajax_category_page(request, category_slug, page):
    if request.method == 'GET':
        mimetype = 'application/json'
        category = Category.objects.get(slug=category_slug)
        news = News.objects.filter(category=category)
        pager = get_page(news, 5, page)
        slug_next = "none"
        if pager.has_next():
            slug_next = reverse('news:category', kwargs={"category_slug": category_slug, "page": pager.next_page_number()})
        arr = []
        for new in pager:
            arr.append(NewsWrapper(new, page=pager.number, slug_next=slug_next))
        return HttpResponse(to_json(arr), mimetype)
Пример #4
0
def index_view(request, page=1):
    news = News.objects.all()
    pager = get_page(news, 5, page)
    categories = Category.objects.all()
    return render_to_response('html/news.html', {"news": pager,
                                                 "categories": categories})