Adding an Atom RSS feed for all media on the server
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Tue, 27 Mar 2012 20:58:58 +0000 (15:58 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 22 Feb 2013 21:04:52 +0000 (15:04 -0600)
Go to /atom/ in your browser to see it.

mediagoblin/listings/routing.py
mediagoblin/listings/views.py

index e5683168e0b1c7413cd9b134a6e00809d2235575..f762c6be3fd48fc13e5779b086e52e3b3d9d7d53 100644 (file)
@@ -19,5 +19,10 @@ from mediagoblin.tools.routing import add_route
 add_route('mediagoblin.listings.tags_listing',
           "/tag/<string:tag>/",
           "mediagoblin.listings.views:tag_listing")
+
+# Atom feeds:
 add_route('mediagoblin.listings.tag_atom_feed', "/tag/<string: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")
index d37161fc32036082e818e5c5eb4efdbf31204d44..a09aa24d6ae471157e613dfaf03ef8575392a9ff 100644 (file)
@@ -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: