rss.py
80 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
/ boards / rss.py
|
r89 | from django.contrib.syndication.views import Feed | ||
from django.core.urlresolvers import reverse | ||||
from django.shortcuts import get_object_or_404 | ||||
|
r203 | from boards.models import Post, Tag | ||
|
r89 | from neboard import settings | ||
__author__ = 'neko259' | ||||
|
r333 | |||
|
r203 | # TODO Make tests for all of these | ||
class AllThreadsFeed(Feed): | ||||
|
r89 | |||
title = settings.SITE_NAME + ' - All threads' | ||||
link = '/' | ||||
description_template = 'boards/rss/post.html' | ||||
def items(self): | ||||
|
r333 | return Post.objects.get_threads(order_by='-pub_time') | ||
|
r89 | |||
def item_title(self, item): | ||||
|
r400 | return item.get_opening_post().title | ||
|
r89 | |||
def item_link(self, item): | ||||
|
r400 | return reverse('thread', args={item.get_opening_post().id}) | ||
|
r89 | |||
def item_pubdate(self, item): | ||||
return item.pub_time | ||||
class TagThreadsFeed(Feed): | ||||
|
r203 | |||
|
r89 | link = '/' | ||
description_template = 'boards/rss/post.html' | ||||
def items(self, obj): | ||||
|
r203 | return Post.objects.get_threads(tag=obj, | ||
|
r224 | order_by='-pub_time') | ||
|
r89 | |||
def get_object(self, request, tag_name): | ||||
return get_object_or_404(Tag, name=tag_name) | ||||
def item_title(self, item): | ||||
|
r400 | return item.get_opening_post().title | ||
|
r89 | |||
def item_link(self, item): | ||||
|
r400 | return reverse('thread', args={item.get_opening_post().id}) | ||
|
r89 | |||
def item_pubdate(self, item): | ||||
return item.pub_time | ||||
def title(self, obj): | ||||
return obj.name | ||||
class ThreadPostsFeed(Feed): | ||||
|
r203 | |||
|
r89 | link = '/' | ||
description_template = 'boards/rss/post.html' | ||||
def items(self, obj): | ||||
|
r400 | return get_object_or_404(Post, id=obj).thread_new.get_replies() | ||
|
r89 | |||
def get_object(self, request, post_id): | ||||
return post_id | ||||
def item_title(self, item): | ||||
return item.title | ||||
def item_link(self, item): | ||||
|
r203 | if item.thread: | ||
|
r400 | return reverse('thread', args={item.thread.get_opening_post() | ||
.id}) + "#" + str(item.id) | ||||
|
r203 | else: | ||
|
r89 | return reverse('thread', args={item.id}) | ||
def item_pubdate(self, item): | ||||
return item.pub_time | ||||
def title(self, obj): | ||||
|
r213 | return get_object_or_404(Post, id=obj).title | ||