forked from hovel/pybbm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeds.py
50 lines (35 loc) · 1.53 KB
/
feeds.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.utils.feedgenerator import Atom1Feed
from django.utils.translation import ugettext_lazy as _
from pybb.models import Post, Topic
from pybb.permissions import perms
class PybbFeed(Feed):
feed_type = Atom1Feed
def link(self):
return reverse('pybb:index')
def item_guid(self, obj):
return str(obj.id)
def item_pubdate(self, obj):
return obj.created
class LastPosts(PybbFeed):
title = _('Latest posts on forum')
description = _('Latest posts on forum')
title_template = 'pybb/feeds/posts_title.html'
description_template = 'pybb/feeds/posts_description.html'
def get_object(self, request, *args, **kwargs):
return request.user
def items(self, user):
ids = [p.id for p in perms.filter_posts(user, Post.objects.only('id')).order_by('-created', '-id')[:15]]
return Post.objects.filter(id__in=ids).select_related('topic', 'topic__forum', 'user')
class LastTopics(PybbFeed):
title = _('Latest topics on forum')
description = _('Latest topics on forum')
title_template = 'pybb/feeds/topics_title.html'
description_template = 'pybb/feeds/topics_description.html'
def get_object(self, request, *args, **kwargs):
return request.user
def items(self, user):
return perms.filter_topics(user, Topic.objects.all()).select_related('forum').order_by('-created', '-id')[:15]