Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve feed functionality

  • Loading branch information...
commit 8c28eb75f05f610845857cd25d109dd0a3b21322 1 parent ad14634
@lorien lorien authored
View
36 pybb/feeds.py
@@ -1,14 +1,12 @@
-from django.contrib.syndication.feeds import Feed
-from django.utils.feedgenerator import Atom1Feed
+from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext as _
+from django.shortcuts import get_object_or_404
-from pybb.models import Post, Topic
+from pybb.models import Post, Topic, Forum
class PybbFeed(Feed):
- feed_type = Atom1Feed
-
def link(self):
return reverse('pybb_index')
@@ -19,7 +17,7 @@ def item_pubdate(self, obj):
return obj.created
-class LastPosts(PybbFeed):
+class LatestPostFeed(PybbFeed):
title = _('Latest posts on forum')
description = _('Latest posts on forum')
title_template = 'pybb/feeds/posts_title.html'
@@ -29,7 +27,7 @@ def items(self):
return Post.objects.order_by('-created')[:15]
-class LastTopics(PybbFeed):
+class LatestTopicFeed(PybbFeed):
title = _('Latest topics on forum')
description = _('Latest topics on forum')
title_template = 'pybb/feeds/topics_title.html'
@@ -37,3 +35,25 @@ class LastTopics(PybbFeed):
def items(self):
return Topic.objects.order_by('-created')[:15]
+
+
+class PybbForumFeed(PybbFeed):
+ title_template = 'pybb/feeds/forum_post_title.html'
+ description_template = 'pybb/feeds/forum_post_description.html'
+
+class ForumFeed(PybbForumFeed):
+ def title(self, obj):
+ return _(u'Latest topics in %s forum' % obj)
+
+ def items(self, obj):
+ return obj.topics.all().order_by('-created')[:15]
+
+
+class ForumByTagFeed(ForumFeed):
+ def get_object(self, request, slug):
+ return get_object_or_404(Forum, slug=slug)
+
+
+class ForumByIdFeed(ForumFeed):
+ def get_object(self, request, pk):
+ return get_object_or_404(Forum, pk=pk)
View
7 pybb/templates/pybb/_category_row.html
@@ -3,9 +3,10 @@ <h2 class="name"><a href="{{ category.get_absolute_url }}">{{ category }}</a></h
<table class="forum-list">
<thead>
<tr>
- <th>Название</th>
- <th>Ответы</th>
- <th>Последний ответ</th>
+ <th class="name">Название</th>
+ <th class="feed">Фид</th>
+ <th class="post-count">Ответы</th>
+ <th class="recent-info">Последний ответ</th>
</tr>
</thead>
<tbody>
View
1  pybb/templates/pybb/_forum_row.html
@@ -6,6 +6,7 @@
<span class="name"><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></span>
<div class="description">{{ forum.description|safe }}</div>
</td>
+ <td class="feed"><a href="{% url pybb_feed_forum_byid_topic forum.pk %}"><img src="{{ MEDIA_URL }}img/feed-icon-small.png" /></a></td>
<td class="post-count">{{ forum.post_count }}</td>
<td class="recent-info">
{% if forum.updated %}{% pybb_time forum.updated %}{% endif %}
View
4 pybb/templates/pybb/base.html
@@ -12,8 +12,8 @@
{% block pybb_extra_css %}{% endblock %}
<!-- Feeds -->
- <link rel="alternate" type="application/atom+xml" href="{% url pybb_feed "posts" %}" title="{% trans "Latest posts on forum" %}" />
- <link rel="alternate" type="application/atom+xml" href="{% url pybb_feed "topics" %}" title="{% trans "Latest topics on forum" %}" />
+ <link rel="alternate" type="application/atom+xml" href="{% url pybb_feed_post %}" title="{% trans "Latest posts on forum" %}" />
+ <link rel="alternate" type="application/atom+xml" href="{% url pybb_feed_topic %}" title="{% trans "Latest topics on forum" %}" />
<!-- Javascript -->
<script type="text/javascript" src="{{ PYBB_MEDIA_URL }}js/jquery-1.4.3.js"></script>
View
1  pybb/templates/pybb/feeds/forum_post_description.html
@@ -0,0 +1 @@
+{% load pybb_tags %}{% pybb_render_post obj.head %}
View
1  pybb/templates/pybb/feeds/forum_post_title.html
@@ -0,0 +1 @@
+{{ obj.name|safe }} @ {{ obj.created|date }}
View
13 pybb/urls.py
@@ -1,18 +1,15 @@
from django.conf.urls.defaults import *
from pybb import views
-from pybb.feeds import LastPosts, LastTopics
+from pybb import feeds
-feeds = {
- 'posts': LastPosts,
- 'topics': LastTopics,
-}
-
urlpatterns = patterns('',
# Syndication feeds
- url('^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
- {'feed_dict': feeds}, name='pybb_feed'),
+ url('^feed/all/post$', feeds.LatestPostFeed(), name='pybb_feed_post'),
+ url('^feed/all/topic$', feeds.LatestTopicFeed(), name='pybb_feed_topic'),
+ url('^feed/forum/tag/(\w+)/topic$', feeds.ForumByTagFeed(), name='pybb_feed_forum_bytag_topic'),
+ url('^feed/forum/id/(\d+)/topic$', feeds.ForumByIdFeed(), name='pybb_feed_forum_byid_topic'),
)
urlpatterns += patterns('pybb.views',
Please sign in to comment.
Something went wrong with that request. Please try again.