From 89cae2bcb5610fa50d70e47bf74853bb04dbca9c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 8 Jun 2010 10:52:53 -0500 Subject: Update feeds to new 1.2 framework Feeds are now views-based and don't need the dictionary anymore. get_object() now takes named arguments as well making it a bit more understandable when reading the code. Signed-off-by: Dan McGee --- feeds.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'feeds.py') diff --git a/feeds.py b/feeds.py index 32190a7b..0bb0e352 100644 --- a/feeds.py +++ b/feeds.py @@ -1,28 +1,27 @@ import datetime -from django.contrib.syndication.feeds import Feed, FeedDoesNotExist +from django.contrib.syndication.feeds import FeedDoesNotExist +from django.contrib.syndication.views import Feed from django.db.models import Q from main.models import Arch, Repo, Package, News class PackageFeed(Feed): link = '/packages/' + title_template = 'feeds/packages_title.html' + description_template = 'feeds/packages_description.html' - def get_object(self, bits): - # just cut the BS early - if len(bits) > 2: - raise FeedDoesNotExist - + def get_object(self, request, arch='', repo=''): obj = dict() qs = Package.objects.select_related('arch', 'repo').order_by('-last_update') - if len(bits) > 0: + if arch != '': # feed for a single arch, also include 'any' packages everywhere - a = Arch.objects.get(name=bits[0]) + a = Arch.objects.get(name=arch) qs = qs.filter(Q(arch=a) | Q(arch__name__iexact='any')) obj['arch'] = a - if len(bits) > 1: + if repo != '': # feed for a single arch AND repo - r = Repo.objects.get(name=bits[1]) + r = Repo.objects.get(name=repo) qs = qs.filter(repo=r) obj['repo'] = r obj['qs'] = qs[:50] @@ -61,6 +60,8 @@ class NewsFeed(Feed): title = 'Arch Linux: Recent news updates' link = '/news/' description = 'The latest and greatest news from the Arch Linux distribution.' + title_template = 'feeds/news_title.html' + description_template = 'feeds/news_description.html' def items(self): return News.objects.select_related('author').order_by('-postdate', '-id')[:10] @@ -73,4 +74,3 @@ class NewsFeed(Feed): return item.author.get_full_name() # vim: set ts=4 sw=4 et: - -- cgit v1.2.3-55-g3dc8