83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
"""RSS and Atom Feeds to subscribe to the latest news or comments."""
|
|
import django_comments as comments
|
|
from django.conf import settings
|
|
from django.contrib.syndication.views import Feed
|
|
from django.utils.feedgenerator import Rss201rev2Feed
|
|
from django.utils.translation import gettext as _
|
|
|
|
from content.models import Article
|
|
|
|
MAX_ARTICLE_ITEMS = 10 # Maximum count of articles in the news RSS feed.
|
|
MAX_COMMENT_ITEMS = 40 # Maximum count of comments in the comments RSS feed.
|
|
|
|
|
|
# Start ignoring PyLintBear (R0201)
|
|
class LatestNews(Feed):
|
|
""" An Feed with the latest news from this site """
|
|
link = "http://www.kasu.at/"
|
|
description = _("Current news from Kasu")
|
|
title = "Kasu - traditonelle asiatische Spielkultur"
|
|
feed_type = Rss201rev2Feed
|
|
|
|
def items(self):
|
|
"""get the newest published news articles for the feed."""
|
|
return Article.objects.published()[:MAX_ARTICLE_ITEMS]
|
|
|
|
def item_title(self, item):
|
|
"""Return the article headline as title."""
|
|
return item.headline
|
|
|
|
def item_author_name(self, item):
|
|
"""Return the username from the author of this article."""
|
|
return item.author.username
|
|
|
|
def item_categories(self, item):
|
|
"""Return the name of the category to which this article belongs."""
|
|
return item.category.name,
|
|
|
|
def item_description(self, item):
|
|
"""Return the main content of the article."""
|
|
return item.content
|
|
|
|
def item_pubdate(self, item):
|
|
"""Return the creation date as date of publication."""
|
|
return item.date_created
|
|
|
|
|
|
class LatestComments(Feed):
|
|
"""Feed of latest comments on the current site."""
|
|
|
|
link = "http://www.kasu.at/"
|
|
description = _("Latest comments on kasu.at")
|
|
title = _("Kasu - latest comments")
|
|
feed_type = Rss201rev2Feed
|
|
|
|
def items(self):
|
|
"""Get the newest published comments for the feed."""
|
|
qs = comments.get_model().objects.filter(
|
|
site__pk=settings.SITE_ID,
|
|
is_public=True, is_removed=False
|
|
)
|
|
return qs.order_by('-submit_date')[:MAX_COMMENT_ITEMS]
|
|
|
|
def item_author_name(self, item):
|
|
"""Return the username of the comment author."""
|
|
return item.user_name
|
|
|
|
def item_description(self, item):
|
|
"""Return the whole comment text."""
|
|
return item.comment
|
|
|
|
def item_pubdate(self, item):
|
|
"""Return the submit date as publication date."""
|
|
return item.submit_date
|
|
|
|
def item_title(self, item):
|
|
"""Return the author and the pagetitle that has been commented."""
|
|
return 'From %(user_name)s in %(content_object)s' % {
|
|
'user_name': item.user_name,
|
|
'content_object': item.content_object
|
|
}
|
|
|
|
# Stop ignoring
|