modified atomfeed feature, corrected spacing, url generation, routing id
authorBernhard Keller <keller_bernhard@web.de>
Mon, 23 May 2011 17:00:46 +0000 (19:00 +0200)
committerBernhard Keller <keller_bernhard@web.de>
Mon, 23 May 2011 17:00:46 +0000 (19:00 +0200)
mediagoblin/templates/mediagoblin/base.html
mediagoblin/templates/mediagoblin/user_pages/user.html
mediagoblin/user_pages/routing.py
mediagoblin/user_pages/views.py

index 4b634cf170c4b8f1ea401c2d513a7e30941dada7..c4bc136495c5adf5191d830532961d16a3d9eaac 100644 (file)
@@ -20,6 +20,8 @@
     <title>{% block title %}MediaGoblin{% endblock title %}</title>
     <link rel="stylesheet" type="text/css"
           href="{{ request.staticdirect('/css/base.css') }}"/>
+    {% block mediagoblin_head %}
+    {% endblock mediagoblin_head %}
   </head>
 
   <body>
index d1809e8016f39b077ae35c729569e729a4f59679..2d09f685a8d3208765f43bb75556bdbfe8b842f4 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #}
 {% extends "mediagoblin/base.html" %}
+
+{% block mediagoblin_head %}
+    <link rel="alternate" type="application/atom+xml"
+          href="{{ request.urlgen(
+                      'mediagoblin.user_pages.atom_feed',
+                       user=user.username) }}">
+{% endblock mediagoblin_head %}
+
 {% block mediagoblin_content -%}
   {% if user %}
     <h1>User page for '{{ user.username }}'</h1>
@@ -25,6 +33,9 @@
       {% include "mediagoblin/utils/object_gallery.html" %}
 
     </ul>
+    <a href={{ request.urlgen(
+                   'mediagoblin.user_pages.atom_feed',
+                   user=user.username) }}> atom feed</a>
   {% else %}
     {# This *should* not occur as the view makes sure we pass in a user. #}
     <p>Sorry, no such user found.<p/>
index 8b535d13beb11d29e77f28db8b3ef940aa5c9459..96f97427273b1d495684685457b00b0830cbf446 100644 (file)
@@ -21,4 +21,6 @@ user_routes = [
         controller="mediagoblin.user_pages.views:user_home"),
     Route('mediagoblin.user_pages.media_home', '/{user}/m/{media}/',
         requirements=dict(m_id="[0-9a-fA-F]{24}"),
-        controller="mediagoblin.user_pages.views:media_home")]
+        controller="mediagoblin.user_pages.views:media_home"),
+    Route('mediagoblin.user_pages.atom_feed', '/{user}/atom/',
+        controller="mediagoblin.user_pages.views:atom_feed")]
index 41bdb40239f4cf663588cfc827c67a47302fb11e..cc9c7b211c71dd55258d8a6beb39473009123713 100644 (file)
@@ -20,6 +20,7 @@ from mediagoblin.util import Pagination
 
 from mediagoblin.decorators import uses_pagination, get_user_media_entry
 
+from werkzeug.contrib.atom import AtomFeed
 
 @uses_pagination
 def user_home(request, page):
@@ -61,3 +62,36 @@ def media_home(request, media):
         template.render(
             {'request': request,
              'media': media}))
+
+ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 5
+
+def atom_feed(request):
+    """
+    generates the atom feed with the newest images
+    """
+
+    user = request.db.User.find_one({
+               'username': request.matchdict['user'],
+               'status': 'active'})
+    if not user:
+       return exc.HTTPNotFound()
+
+    cursor = request.db.MediaEntry.find({
+                 'uploader': user['_id'],
+                 'state': 'processed'}) \
+                 .sort('created', DESCENDING) \
+                 .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
+
+    feed = AtomFeed(request.matchdict['user'],
+               feed_url=request.url,
+               url=request.host_url)
+            
+    for entry in cursor:
+        feed.add(entry.get('title'),
+            entry.get('description'),
+            content_type='html',
+            author=request.matchdict['user'],
+            updated=entry.get('created'),
+            url=entry.url_for_self(request.urlgen))
+
+    return feed.get_response()