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 +++++++++++----------- urls.py | 14 ++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) 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 @@ def item_author_name(self, item): return item.author.get_full_name() # vim: set ts=4 sw=4 et: - diff --git a/urls.py b/urls.py index 8fe7d7d9..64e60ccb 100644 --- a/urls.py +++ b/urls.py @@ -10,12 +10,6 @@ from feeds import PackageFeed, NewsFeed from sitemaps import NewsSitemap, PackagesSitemap, PackageFilesSitemap - -feeds = { - 'news': NewsFeed, - 'packages': PackageFeed, -} - sitemaps = { 'news': NewsSitemap, 'packages': PackagesSitemap, @@ -85,8 +79,12 @@ # Feeds and sitemaps (r'^feeds/$', 'public.views.feeds', {}, 'feeds-list'), - (r'^feeds/(?P.*)/$', - 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), + (r'^feeds/news/$', NewsFeed()), + (r'^feeds/packages/$', PackageFeed()), + (r'^feeds/packages/(?P[A-z0-9]+)/$', + PackageFeed()), + (r'^feeds/packages/(?P[A-z0-9]+)/(?P[A-z0-9\-]+)/$', + PackageFeed()), (r'^sitemap.xml$', 'django.contrib.sitemaps.views.index', {'sitemaps': sitemaps}), (r'^sitemap-(?P
.+)\.xml$', 'django.contrib.sitemaps.views.sitemap', -- cgit v1.2.3-54-g00ecf