diff options
-rw-r--r-- | feeds.py | 60 | ||||
-rw-r--r-- | public/views.py | 7 | ||||
-rw-r--r-- | templates/public/feeds.html | 27 | ||||
-rw-r--r-- | templates/public/index.html | 3 | ||||
-rw-r--r-- | urls.py | 1 |
5 files changed, 88 insertions, 10 deletions
@@ -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): diff --git a/public/views.py b/public/views.py index 5c05782d..d4a1c80c 100644 --- a/public/views.py +++ b/public/views.py @@ -72,5 +72,12 @@ def moreforums(request): template_name="public/moreforums.html", template_object_name="forum") +def feeds(request): + context = { + 'arches': Arch.objects.all(), + 'repos': Repo.objects.all(), + } + return render_to_response('public/feeds.html', context) + # vim: set ts=4 sw=4 et: diff --git a/templates/public/feeds.html b/templates/public/feeds.html new file mode 100644 index 00000000..a63c9eae --- /dev/null +++ b/templates/public/feeds.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} +{% block title %}Arch Linux - RSS Feeds{% endblock %} +{% block content %} +<div class="box"> + <h2 class="title">RSS Feeds</h2> + <br /><br /> + <p>Several RSS feeds are available for consumption from the Arch website. + The majority of these are package related and allow feeds to be customized + for the updates you care about.</p> + <table cellspacing="20"> + <tr><td>News items feed</td> + <td><a href="/feeds/news/">Feed <img src="/media/rss.png" alt="RSS Feed" /></a></td></tr> + <tr><td>Packages feed for <em>all</em> architectures, <em>all</em> repositories</td> + <td><a href="/feeds/packages/">Feed <img src="/media/rss.png" alt="RSS Feed" /></a></td></tr> + {% for arch in arches %} + <tr><td>Packages feed for architecture {{ arch }}, <em>all</em> repositories</td> + <td><a href="/feeds/packages/{{ arch }}/">Feed <img src="/media/rss.png" alt="RSS Feed" /></a></td></tr> + {% for repo in repos %} + <tr><td>Packages feed for architecture {{ arch }}, repository {{ repo }}</td> + <td><a href="/feeds/packages/{{ arch }}/{{ repo }}/">Feed <img src="/media/rss.png" alt="RSS Feed" /></a></td></tr> + {% endfor %} + {% endfor %} + </table> +</div> +<br /><br /> +{% endblock %} + diff --git a/templates/public/index.html b/templates/public/index.html index 9351a722..0bc0af45 100644 --- a/templates/public/index.html +++ b/templates/public/index.html @@ -64,7 +64,8 @@ </tr> {% endfor %} <tr> - <td colspan="2" style="text-align:right;font-size:x-small"><br /><a href="/packages/?sort=-last_update">More...</a></td> + <td style="font-size:x-small"><br /><a href="/feeds/">More Feeds...</a></td> + <td style="text-align:right;font-size:x-small"><br /><a href="/packages/?sort=-last_update">More Updates...</a></td> </tr> </table> </div> @@ -78,6 +78,7 @@ urlpatterns = patterns('', (r'^devel/newuser/$', 'archweb.devel.views.new_user_form'), # Feeds and sitemaps + (r'^feeds/$', 'archweb.public.views.feeds'), (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', |