# HG changeset patch # User neko259 # Date 2013-06-24 09:13:06 # Node ID 84c3312470822eff70da6df77b2c8544fa49ede5 # Parent f32104ea2d782adb7c41b55a13543dccd927ead6 Implemented RSS support. This fixes #11 diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -2,7 +2,7 @@ import markdown from markdown.inlinepatterns import Pattern from markdown.util import etree -__author__ = 'vurdalak' +__author__ = 'neko259' class AutolinkPattern(Pattern): diff --git a/boards/rss.py b/boards/rss.py new file mode 100644 --- /dev/null +++ b/boards/rss.py @@ -0,0 +1,74 @@ +from django.contrib.syndication.views import Feed +from django.core.urlresolvers import reverse +from django.shortcuts import get_object_or_404 +from boards.models import Post, Tag, NO_PARENT +from neboard import settings + +__author__ = 'neko259' + + +class AllThreadsFeed(Feed): + title = settings.SITE_NAME + ' - All threads' + link = '/' + description_template = 'boards/rss/post.html' + + def items(self): + return Post.objects.get_threads(order_by='-pub_time') + + def item_title(self, item): + return item.title + + def item_link(self, item): + return reverse('thread', args={item.id}) + + def item_pubdate(self, item): + return item.pub_time + + +class TagThreadsFeed(Feed): + link = '/' + description_template = 'boards/rss/post.html' + + def items(self, obj): + return Post.objects.get_threads(tag=obj, order_by='-pub_time') + + def get_object(self, request, tag_name): + return get_object_or_404(Tag, name=tag_name) + + def item_title(self, item): + return item.title + + def item_link(self, item): + return reverse('thread', args={item.id}) + + def item_pubdate(self, item): + return item.pub_time + + def title(self, obj): + return obj.name + + +class ThreadPostsFeed(Feed): + link = '/' + description_template = 'boards/rss/post.html' + + def items(self, obj): + return Post.objects.get_thread(opening_post_id=obj) + + def get_object(self, request, post_id): + return post_id + + def item_title(self, item): + return item.title + + def item_link(self, item): + if NO_PARENT == item.parent: + return reverse('thread', args={item.id}) + else: + return reverse('thread', args={item.parent}) + "#" + str(item.id) + + def item_pubdate(self, item): + return item.pub_time + + def title(self, obj): + return get_object_or_404(Post, id=obj).title \ No newline at end of file diff --git a/boards/templates/boards/base.html b/boards/templates/boards/base.html --- a/boards/templates/boards/base.html +++ b/boards/templates/boards/base.html @@ -38,6 +38,7 @@ diff --git a/boards/templates/boards/rss/post.html b/boards/templates/boards/rss/post.html new file mode 100644 --- /dev/null +++ b/boards/templates/boards/rss/post.html @@ -0,0 +1,15 @@ +{% load i18n %} + +{% if obj.image %} +{% trans 'Post image' %} +{% endif %} +{{ obj.text.rendered|safe }} +{% if obj.tags.all %} +

+ {% trans 'Tags' %}: + {% for tag in obj.tags.all %} + {{ tag.name }} + {% endfor %} +

+{% endif %} \ No newline at end of file diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -167,7 +167,7 @@ class BoardTests(TestCase): 'where it should fail') response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT, - 'tags': valid_tags}) + 'tags': valid_tags}) self.assertEqual(HTTP_CODE_REDIRECT, response.status_code, msg=u'Posting new message failed: got code ' + str(response.status_code)) diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -1,5 +1,6 @@ from django.conf.urls import patterns, url, include from boards import views +from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed urlpatterns = patterns('', @@ -23,4 +24,9 @@ urlpatterns = patterns('', url(r'^settings$', views.settings, name='settings'), url(r'^tags$', views.all_tags, name='tags'), url(r'^captcha/', include('captcha.urls')), + + # RSS feeds + url(r'^rss/$', AllThreadsFeed()), + url(r'^tag/(?P\w+)/rss/$', TagThreadsFeed()), + url(r'^thread/(?P\w+)/rss/$', ThreadPostsFeed()), ) \ No newline at end of file diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -128,7 +128,7 @@ INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', - 'django.contrib.sites', + # 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: