rss.py
84 lines
| 2.2 KiB
| text/x-python
|
PythonLexer
/ boards / rss.py
neko259
|
r89 | from django.contrib.syndication.views import Feed | ||
from django.core.urlresolvers import reverse | ||||
from django.shortcuts import get_object_or_404 | ||||
neko259
|
r596 | from boards.models import Post, Tag, Thread | ||
neko259
|
r716 | from boards import settings | ||
neko259
|
r1414 | from boards.models.thread import STATUS_ARCHIVE | ||
neko259
|
r89 | |||
neko259
|
r1400 | __author__ = 'nekorin' | ||
MAX_ITEMS = settings.get_int('RSS', 'MaxItems') | ||||
neko259
|
r89 | |||
neko259
|
r333 | |||
neko259
|
r203 | # TODO Make tests for all of these | ||
class AllThreadsFeed(Feed): | ||||
neko259
|
r89 | |||
neko259
|
r1153 | title = settings.get('Version', 'SiteName') + ' - All threads' | ||
neko259
|
r89 | link = '/' | ||
description_template = 'boards/rss/post.html' | ||||
def items(self): | ||||
neko259
|
r1414 | return Thread.objects.exclude(status=STATUS_ARCHIVE).order_by('-id')[:MAX_ITEMS] | ||
neko259
|
r89 | |||
def item_title(self, item): | ||||
neko259
|
r400 | return item.get_opening_post().title | ||
neko259
|
r89 | |||
def item_link(self, item): | ||||
neko259
|
r626 | return reverse('thread', args={item.get_opening_post_id()}) | ||
neko259
|
r89 | |||
def item_pubdate(self, item): | ||||
neko259
|
r419 | return item.get_pub_time() | ||
neko259
|
r89 | |||
class TagThreadsFeed(Feed): | ||||
neko259
|
r203 | |||
neko259
|
r89 | link = '/' | ||
description_template = 'boards/rss/post.html' | ||||
def items(self, obj): | ||||
neko259
|
r1414 | return obj.get_threads().exclude(status=STATUS_ARCHIVE).order_by('-id')[:MAX_ITEMS] | ||
neko259
|
r89 | |||
def get_object(self, request, tag_name): | ||||
return get_object_or_404(Tag, name=tag_name) | ||||
def item_title(self, item): | ||||
neko259
|
r400 | return item.get_opening_post().title | ||
neko259
|
r89 | |||
def item_link(self, item): | ||||
neko259
|
r626 | return reverse('thread', args={item.get_opening_post_id()}) | ||
neko259
|
r89 | |||
def item_pubdate(self, item): | ||||
neko259
|
r402 | return item.get_pub_time() | ||
neko259
|
r89 | |||
def title(self, obj): | ||||
return obj.name | ||||
class ThreadPostsFeed(Feed): | ||||
neko259
|
r203 | |||
neko259
|
r89 | link = '/' | ||
description_template = 'boards/rss/post.html' | ||||
def items(self, obj): | ||||
neko259
|
r1400 | return obj.get_thread().get_replies().order_by('-pub_time')[:MAX_ITEMS] | ||
neko259
|
r89 | |||
def get_object(self, request, post_id): | ||||
neko259
|
r580 | return get_object_or_404(Post, id=post_id) | ||
neko259
|
r89 | |||
def item_title(self, item): | ||||
return item.title | ||||
def item_link(self, item): | ||||
neko259
|
r402 | if not item.is_opening(): | ||
neko259
|
r626 | return reverse('thread', args={ | ||
item.get_thread().get_opening_post_id() | ||||
}) + "#" + str(item.id) | ||||
neko259
|
r203 | else: | ||
neko259
|
r89 | return reverse('thread', args={item.id}) | ||
def item_pubdate(self, item): | ||||
return item.pub_time | ||||
def title(self, obj): | ||||
neko259
|
r580 | return obj.title | ||