From 1df68a3524d92caee5601a8acc011ac8e1fe16d4 Mon Sep 17 00:00:00 2001 From: Michele Azzolari Date: Thu, 5 Jan 2012 18:48:23 +0100 Subject: [PATCH] Fixed #724 and added extra infos to the atom feed (author uri and links to the html version of each entry) --- mediagoblin/db/mongo/models.py | 8 +++++--- mediagoblin/listings/views.py | 24 ++++++++++++++++++++---- mediagoblin/user_pages/views.py | 28 ++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/mediagoblin/db/mongo/models.py b/mediagoblin/db/mongo/models.py index 5de59c12..f1e8eae6 100644 --- a/mediagoblin/db/mongo/models.py +++ b/mediagoblin/db/mongo/models.py @@ -255,7 +255,7 @@ class MediaEntry(Document): if duplicate: self.slug = "%s-%s" % (self._id, self.slug) - def url_for_self(self, urlgen): + def url_for_self(self, urlgen, **extra_args): """ Generate an appropriate url for ourselves @@ -267,12 +267,14 @@ class MediaEntry(Document): return urlgen( 'mediagoblin.user_pages.media_home', user=uploader.username, - media=self.slug) + media=self.slug, + **extra_args) else: return urlgen( 'mediagoblin.user_pages.media_home', user=uploader.username, - media=unicode(self._id)) + media=unicode(self._id), + **extra_args) def url_to_prev(self, urlgen): """ diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 3ecf06f4..ca8e8229 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -77,17 +77,33 @@ def tag_atom_feed(request): cursor = cursor.sort('created', DESCENDING) 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_url=request.url, - url=request.host_url) - + id='tag:'+request.host+',2011:gallery.tag-%s' % tag_slug, + links=[{'href': request.urlgen( + 'mediagoblin.listings.tags_listing', + qualified=True, tag=tag_slug ), + 'rel': 'alternate', + 'type': 'text/html'}]) for entry in cursor: feed.add(entry.get('title'), entry.get('description_html'), + id=entry.url_for_self(request.urlgen,qualified=True), content_type='html', - author=entry.get_uploader.username, + author={'name': entry.get_uploader.username, + 'uri': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True, user=entry.get_uploader.username)}, updated=entry.get('created'), - url=entry.url_for_self(request.urlgen)) + links=[{ + 'href':entry.url_for_self( + request.urlgen, + qualified=True), + 'rel': 'alternate', + 'type': 'text/html'}]) return feed.get_response() diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index f721f012..a234722f 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -225,17 +225,37 @@ def atom_feed(request): .sort('created', DESCENDING) \ .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) - feed = AtomFeed(request.matchdict['user'], + """ + ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI) + """ + feed = AtomFeed( + "MediaGoblin: Feed for user '%s'" % request.matchdict['user'], feed_url=request.url, - url=request.host_url) + id='tag:'+request.host+',2011:gallery.user-'+request.matchdict['user'], + links=[{ + 'href': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True,user=request.matchdict['user']), + 'rel': 'alternate', + 'type': 'text/html'}]) for entry in cursor: feed.add(entry.get('title'), entry.get('description_html'), + id=entry.url_for_self(request.urlgen,qualified=True), content_type='html', - author=request.matchdict['user'], + author={ + 'name': entry.get_uploader.username, + 'uri': request.urlgen( + 'mediagoblin.user_pages.user_home', + qualified=True, user=entry.get_uploader.username)}, updated=entry.get('created'), - url=entry.url_for_self(request.urlgen)) + links=[{ + 'href': entry.url_for_self( + request.urlgen, + qualified=True), + 'rel': 'alternate', + 'type': 'text/html'}]) return feed.get_response() -- 2.25.1