from datetime import datetime, time from django.conf import settings from django.utils.translation import ugettext as _ from django.contrib import comments from django.contrib.syndication.views import Feed from django.utils.feedgenerator import Rss201rev2Feed from models import Article # noinspection PyMethodMayBeStatic class LatestNews(Feed): link = "http://www.kasu.at/" description = _("Current news from Kasu") title = "Kasu - traditonelle asiatische Spielkultur" feed_type = Rss201rev2Feed def items(self): return Article.objects.published()[:10] def item_title(self, item): return item.headline def item_author_name(self, item): return item.author.username def item_categories(self, item): return item.category.name, def item_description(self, item): return item.content def item_pubdate(self, item): return datetime.combine(item.date_created, time()) # noinspection PyMethodMayBeStatic 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): qs = comments.get_model().objects.filter( site__pk=settings.SITE_ID, is_public=True, is_removed=False ) return qs.order_by('-submit_date')[:40] def item_author_name(self, item): return item.user_name def item_description(self, item): return item.comment def item_pubdate(self, item): return item.submit_date def item_title(self, item): return 'From %(user_name)s in %(content_object)s' % { 'user_name': item.user_name, 'content_object': item.content_object }