4
4
from django.utils.feedgenerator import Atom1Feed
5
5
from pybb.models import Post, Topic, Forum
7
8
class PybbFeed(Feed):
8
9
feed_type = Atom1Feed
11
12
if obj == self.all_objects:
12
13
return self.all_title
14
15
return self.one_title % obj.name
16
17
def items(self, obj):
17
18
if obj == self.all_objects:
18
19
return obj.order_by('-created')[:15]
20
21
return self.items_for_object(obj)
22
23
def link(self, obj):
23
24
if obj == self.all_objects:
24
25
return reverse('pybb_index')
25
return "/ewfwevw%s" % reverse('pybb_forum', args=(obj.pk,))
26
return '/ewfwevw%s' % reverse('pybb_forum', args=(obj.pk,))
27
def get_object(self,request, *args, **kwargs):
29
Implement getting feeds for a specific subforum
28
def get_object(self, request, *args, **kwargs):
29
"""Implement getting feeds for a specific subforum."""
31
30
if not 'topic_id' in kwargs:
32
31
# Latest Posts/Topics on all forums
33
32
return self.all_objects
35
34
# Latest Posts/Topics for specific Forum
37
forum=Forum.objects.get(pk=int(kwargs['topic_id']))
36
forum = Forum.objects.get(pk=int(kwargs['topic_id']))
41
40
raise ObjectDoesNotExist
43
# Must be used for valid Atom feeds
42
# Must be used for valid Atom feeds
44
43
def item_updateddate(self, obj):
47
46
def item_link(self, item):
48
47
return item.get_absolute_url()
50
49
# Validated through http://validator.w3.org/feed/
51
52
class LastPosts(PybbFeed):
52
53
all_title = 'Latest posts on all forums'
53
54
one_title = 'Latest posts on forum %s'
57
58
all_objects = Post.objects.filter(hidden=False)
59
def items_for_object(self,obj):
60
return Post.objects.filter( hidden = False, topic__forum = obj ).order_by('-created')[:15]
60
def items_for_object(self, obj):
61
return Post.objects.filter(hidden=False, topic__forum=obj).order_by('-created')[:15]
62
63
def item_author_name(self, item):
64
Takes the object returned by get_object and returns the feeds's
65
auhor's name as a Python string
64
"""Takes the object returned by get_object and returns the feeds's
65
auhor's name as a Python string."""
67
66
return item.user.username
69
68
# Validated through http://validator.w3.org/feed/
70
71
class LastTopics(PybbFeed):
71
72
all_title = 'Latest topics on all forums'
72
73
one_title = 'Latest topics on forum %s'
73
74
title_template = 'pybb/feeds/topics_title.html'
74
75
description_template = 'pybb/feeds/topics_description.html'
76
all_objects = Topic.objects.exclude(posts__hidden = True)
78
def items_for_object(self,item):
79
return Topic.objects.exclude( posts__hidden = True ).filter( forum = item ).order_by('-created')[:15]
77
all_objects = Topic.objects.exclude(posts__hidden=True)
79
def items_for_object(self, item):
80
return Topic.objects.exclude(posts__hidden=True).filter(forum=item).order_by('-created')[:15]
81
82
def item_author_name(self, item):
83
Takes the object returned by get_object and returns the feeds's
84
auhor's name as a Python string
83
"""Takes the object returned by get_object and returns the feeds's
84
auhor's name as a Python string."""
86
85
return item.user.username