From 6fe8aec0abdfe284439e9d3adda85da8e5c3825b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 2 Feb 2010 22:36:41 -0600 Subject: feeds: add per arch, per repo feed ability Make the feed framework a lot more flexible and give the possibility to have a feed for each architecture. You can drill down even more than also get a feed for a particular repo; some might find this helpful for something like tracking [testing]. Implements FS#12939. I also bumped up the number of items available in each of these feeds; since it is full of a bunch of small items it might be more helpful to have more available and it should also prevent fewer ones from being missed. The UI isn't exactly spectacular, but I figured some sort of page is better than none listing all the various feeds you can pull from. Signed-off-by: Dan McGee --- feeds.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'feeds.py') diff --git a/feeds.py b/feeds.py index bc8a5b0..e2fe36a 100644 --- a/feeds.py +++ b/feeds.py @@ -1,14 +1,55 @@ import datetime -from django.contrib.syndication.feeds import Feed -from archweb.main.models import Package, News + +from django.contrib.syndication.feeds import Feed, FeedDoesNotExist +from django.db.models import Q +from archweb.main.models import Arch, Repo, Package, News class PackageFeed(Feed): - title = 'Arch Linux Recent Package Updates' - link = '/packages/' - description = 'Recently updated packages in the Arch Linux package repositories.' + def get_object(self, bits): + # just cut the BS early + if len(bits) > 2: + raise FeedDoesNotExist - def items(self): - return Package.objects.select_related('arch', 'repo').order_by('-last_update')[:24] + obj = dict() + qs = Package.objects.select_related('arch', 'repo').order_by('-last_update') + + if len(bits) > 0: + # feed for a single arch, also include 'any' packages everywhere + a = Arch.objects.get(name=bits[0]) + qs = qs.filter(Q(arch=a) | Q(arch__name__iexact='any')) + obj['arch'] = a + if len(bits) > 1: + # feed for a single arch AND repo + r = Repo.objects.get(name=bits[1]) + qs = qs.filter(repo=r) + obj['repo'] = r + obj['qs'] = qs[:50] + return obj + + def title(self, obj): + s = 'Arch Linux: Recent package updates' + if 'repo' in obj: + s += ' (%s [%s])' % (obj['arch'].name, obj['repo'].name.lower()) + elif 'arch' in obj: + s += ' (%s)' % (obj['arch'].name) + return s + + def link(self, obj): + return '/packages/' + + def description(self, obj): + s = 'Recently updated packages in the Arch Linux package repositories' + if 'arch' in obj: + s += ' for the \'%s\' architecture' % obj['arch'].name.lower() + if obj['arch'].name != 'any': + s += ' (including \'any\' packages)' + if 'repo' in obj: + s += ' in the [%s] repository' % obj['repo'].name.lower() + s += '.' + return s + + def items(self, obj): + return obj['qs'] def item_pubdate(self, item): return item.last_update @@ -16,9 +57,10 @@ class PackageFeed(Feed): def item_categories(self, item): return (item.repo.name,item.arch.name) + class NewsFeed(Feed): - title = 'Arch Linux Recent News Updates' - link = '/news/' + title = 'Arch Linux: Recent news updates' + link = '/news/' description = 'The latest and greatest news from the Arch Linux distribution.' def items(self): -- cgit v1.2.3-24-g4f1b