changeset 192:83c2d2f07df4

Atom feed for database submissions.
author Daniele Nicolodi <daniele@grinta.net>
date Sun, 14 Aug 2011 12:23:55 +0200
parents 8d21600963d7
children 215684074923
files src/ltpdarepo/__init__.py src/ltpdarepo/static/feed.png src/ltpdarepo/static/style.css src/ltpdarepo/templates/database.html src/ltpdarepo/views/feed.py
diffstat 5 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/__init__.py	Wed Nov 09 10:39:24 2011 +0100
+++ b/src/ltpdarepo/__init__.py	Sun Aug 14 12:23:55 2011 +0200
@@ -174,6 +174,9 @@
 from .views.browse import module
 app.register_blueprint(module, url_prefix='/browse')
 
+from .views.feed import module
+app.register_blueprint(module, url_prefix='/browse')
+
 from .views.profile import module
 app.register_blueprint(module, url_prefix='/user')
 
Binary file src/ltpdarepo/static/feed.png has changed
--- a/src/ltpdarepo/static/style.css	Wed Nov 09 10:39:24 2011 +0100
+++ b/src/ltpdarepo/static/style.css	Sun Aug 14 12:23:55 2011 +0200
@@ -155,6 +155,15 @@
     border-bottom: 1px solid black;
 }
 
+.content {
+    position: relative;
+}
+
+.feed img {
+    margin: 0.5em 0;
+    border: none;
+}
+
 /** definition lists **/
 
 .data {
--- a/src/ltpdarepo/templates/database.html	Wed Nov 09 10:39:24 2011 +0100
+++ b/src/ltpdarepo/templates/database.html	Sun Aug 14 12:23:55 2011 +0200
@@ -1,4 +1,7 @@
 {% extends "layout.html" %}
+{% block head %}
+<link href="{{ url_for('feed.atom', database=database.id) }}" rel="alternate" title="Recent Submissions" type="application/atom+xml">
+{% endblock %}
 {% block title %}{{ database.id }}{% endblock %}
 {% block body %}
 <h2>Database &#x00AB;{{ database.id }}&#x00BB;</h2>
@@ -24,4 +27,9 @@
   {% endfor %}
 </ul>
 {% endif %}
+<h2>Feed</h2>
+<p class="discrete">Atom feed with the latest submisions to the database:</p>
+<a class="feed" href="{{ url_for('feed.atom', database=database.id) }}">
+  <img src="{{ url_for('static', filename='feed.png') }}"></img>
+</a>
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ltpdarepo/views/feed.py	Sun Aug 14 12:23:55 2011 +0200
@@ -0,0 +1,43 @@
+from flask import Blueprint, request, url_for, g
+from werkzeug.contrib.atom import AtomFeed
+
+from .browse import Objs
+
+from ltpdarepo.database import Database
+from ltpdarepo.security import require, view
+
+app = Blueprint('feed', __name__)
+
+
+@app.route('/<database>/atom.xml')
+@require('user')
+def atom(database):
+    with view('database', database):
+        db = Database.load(id=database)
+        if db is None:
+            # not found
+            abort(404)
+
+        feed = AtomFeed(
+            title=db.id, subtitle=db.description,
+            url=url_for('browse.database', database=database, _external=True),
+            feed_url=request.url,
+            generator=('LTPDA Repository', None, g.version))
+
+        # first n objects ordered per descending submission time
+        objs = Objs(database=database).orderby('submitted', 1).limit(64)
+        
+        for obj in objs.all():
+            obj['url'] = url_for('browse.obj', database=database,
+                                 objid=obj['id'], _external=True)
+            feed.add(title='%s: %s' % (obj['name'], obj['title']),
+                     content='%s %s' % (obj['description'], obj['analysis']),
+                     content_type='text',
+                     author=obj['author'],
+                     url=obj['url'],
+                     updated=obj['submitted'])
+
+        # return with the correct mime type
+        return feed.get_response()
+
+module = app