blob: f621ae8159d2637f1bcd6d1b246a31cd0957e7ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import Http404
from django.shortcuts import render
from aggregator.models import CATEGORIES, Feed, Post
def posts(request, cat=None, page=1):
category = cat or 'all'
posts = Post.objects.all()
feeds = Feed.objects.all()
if category != 'all':
posts = posts.filter(feed__category=CATEGORIES.index(category))
feeds = feeds.filter(category=CATEGORIES.index(category))
paginator = Paginator(posts, 20)
if page is None:
page = 1
try:
object_list = paginator.page(page)
except (EmptyPage, InvalidPage):
raise Http404
ctx = {'list': object_list,
'category': category,
'feeds': feeds}
return render(request, 'aggregator/posts.html', ctx)
|