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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
from django.contrib.syndication.views import Feed
from django.urls import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.utils.feedgenerator import Atom1Feed
from pybb.models import Post, Topic, Forum
class PybbFeed(Feed):
feed_type = Atom1Feed
def title(self, obj):
if obj == self.all_objects:
return self.all_title
else:
return self.one_title % obj.name
def items(self, obj):
if obj == self.all_objects:
return obj.order_by('-created')[:15]
else:
return self.items_for_object(obj)
def link(self, obj):
if obj == self.all_objects:
return reverse('pybb_index')
return '/ewfwevw%s' % reverse('pybb_forum', args=(obj.pk,))
def get_object(self, request, *args, **kwargs):
"""Implement getting feeds for a specific subforum."""
if not 'topic_id' in kwargs:
# Latest Posts/Topics on all forums
return self.all_objects
else:
# Latest Posts/Topics for specific Forum
try:
forum = Forum.objects.get(pk=int(kwargs['topic_id']))
return forum
except ValueError:
pass
raise ObjectDoesNotExist
# Must be used for valid Atom feeds
def item_updateddate(self, obj):
return obj.created
def item_link(self, item):
return item.get_absolute_url()
# Validated through http://validator.w3.org/feed/
class LastPosts(PybbFeed):
all_title = 'Latest posts on all forums'
one_title = 'Latest posts on forum %s'
title_template = 'pybb/feeds/posts_title.html'
description_template = 'pybb/feeds/posts_description.html'
all_objects = Post.objects.filter(hidden=False)
def items_for_object(self, obj):
return Post.objects.filter(hidden=False, topic__forum=obj).order_by('-created')[:15]
def item_author_name(self, item):
"""Takes the object returned by get_object and returns the feeds's
auhor's name as a Python string."""
return item.user.username
# Validated through http://validator.w3.org/feed/
class LastTopics(PybbFeed):
all_title = 'Latest topics on all forums'
one_title = 'Latest topics on forum %s'
title_template = 'pybb/feeds/topics_title.html'
description_template = 'pybb/feeds/topics_description.html'
all_objects = Topic.objects.exclude(posts__hidden=True)
def items_for_object(self, item):
return Topic.objects.exclude(posts__hidden=True).filter(forum=item).order_by('-created')[:15]
def item_author_name(self, item):
"""Takes the object returned by get_object and returns the feeds's
auhor's name as a Python string."""
return item.user.username
|