From b624ca0f8befe7315c9079402b1f598e3f07dd21 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 27 Mar 2012 15:58:58 -0500 Subject: [PATCH] Adding an Atom RSS feed for all media on the server Go to /atom/ in your browser to see it. --- mediagoblin/listings/routing.py | 5 +++++ mediagoblin/listings/views.py | 24 ++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index e5683168..f762c6be 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -19,5 +19,10 @@ from mediagoblin.tools.routing import add_route add_route('mediagoblin.listings.tags_listing', "/tag//", "mediagoblin.listings.views:tag_listing") + +# Atom feeds: add_route('mediagoblin.listings.tag_atom_feed', "/tag//atom/", "mediagoblin.listings.views:tag_atom_feed") +# The all new entries feed +add_route('mediagoblin.listings.atom_feed', '/atom/', + "mediagoblin.listings.views:tag_atom_feed") diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index d37161fc..a09aa24d 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -68,22 +68,26 @@ def tag_atom_feed(request): """ generates the atom feed with the tag images """ - tag_slug = request.matchdict[u'tag'] + tag_slug = request.matchdict.get(u'tag') + feed_title = "MediaGoblin Feed" + if tag_slug: + cursor = media_entries_for_tag_slug(request.db, tag_slug) + link = request.urlgen('mediagoblin.listings.tags_listing', + qualified=True, tag=tag_slug ) + feed_title += "for tag '%s'" % tag_slug, + else: # all recent item feed + cursor = MediaEntry.query.filter_by(state=u'processed') + link = request.urlgen('index', qualified=True) + feed_title += "for all recent items" - cursor = media_entries_for_tag_slug(request.db, tag_slug) cursor = cursor.order_by(MediaEntry.created.desc()) cursor = cursor.limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) - """ - ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) - """ feed = AtomFeed( - "MediaGoblin: Feed for tag '%s'" % tag_slug, + feed_title, feed_url=request.url, - id='tag:'+request.host+',2011:gallery.tag-%s' % tag_slug, - links=[{'href': request.urlgen( - 'mediagoblin.listings.tags_listing', - qualified=True, tag=tag_slug ), + id=link, + links=[{'href': link, 'rel': 'alternate', 'type': 'text/html'}]) for entry in cursor: -- 2.25.1