News feed (atom)
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 6 Aug 2010 13:37:48 +0000 (13:37 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 6 Aug 2010 13:37:48 +0000 (13:37 +0000)
bin/djais/models.py
bin/djais/urls.py
bin/djais/views.py
html_templates/news.atom [new file with mode: 0644]
html_templates/news.html

index cc05218f106d1f4f649e7baa9aa0686bb4d75804..a1e5b638762b27a769efab7d364fbba48ff69e44 100644 (file)
@@ -122,7 +122,8 @@ class FleetVessel(models.Model):
 
 class News(models.Model):
     id = models.AutoField(primary_key=True)
-    t = models.DateTimeField()
+    created = models.DateTimeField()
+    updated = models.DateTimeField()
     title = models.TextField()
     txt = models.TextField()
     class Meta:
index 886bccd92945f6bc903b3f0a6ab03adffdead374..662a41d6b03d793f7f0bfb98dcf2df7d6b3afbe7 100644 (file)
@@ -28,6 +28,7 @@ urlpatterns = patterns('',
     (r'^source/$', 'ais.djais.views.sources_index'),
     (r'^source/stats$', 'ais.djais.views.sources_stats'),
     (r'^news/(?P<page>\d*)$', 'ais.djais.views.news'),
+    (r'^news/feed', 'ais.djais.views.news_atom'),
     (r'^logout$', 'ais.djais.views.logout'),
 
     # Example:
index 361830390d7ef90c1c899ba2e77cd80d7b7441e5..193309f063ac0c92ee222dc2d0fd9c11aaf8670e 100644 (file)
@@ -780,5 +780,18 @@ def news(request, page):
         page = 1
     # TODO __future__
     npages = int((News.objects.count() + NEWS_PER_PAGE - 1) / NEWS_PER_PAGE)
-    last_news = News.objects.order_by('-t')[(page - 1) * NEWS_PER_PAGE : page * NEWS_PER_PAGE]
+    last_news = News.objects.order_by('-created')[(page - 1) * NEWS_PER_PAGE : page * NEWS_PER_PAGE]
     return render_to_response('news.html', {'news':last_news, 'page': page, 'npages': npages}, RequestContext(request))
+
+@http_authenticate(auth, 'ais')
+def news_atom(request):
+    from django.db import connection
+
+    news = News.objects.order_by('-created')
+
+    cursor = connection.cursor()
+    cursor.execute("SELECT MAX(updated) FROM news")
+    row = cursor.fetchone()
+    last_update = row[0]
+
+    return render_to_response('news.atom', {'news':news, 'last_update':last_update}, RequestContext(request), mimetype='application/atom+xml')
diff --git a/html_templates/news.atom b/html_templates/news.atom
new file mode 100644 (file)
index 0000000..0476dc1
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns='http://www.w3.org/2005/Atom'>
+<id>tag:nirgal.com,2000:ais</id>
+<link rel='self' type='application/atom+xml' href='https://ais.nirgal.com/news/feed' />
+<link rel='alternate' type='text/html' href='https://ais.nirgal.com/news/' />
+<title>AIS news</title>
+<subtitle type='text'>AIS ship monitoring news</subtitle>
+<icon uri='https://ais.nirgal.com/aiga_water_transportation.svg' />
+<generator uri='https://ais.nirgal.com/svn'>AIS software</generator>
+<updated>{{ last_update|date:"Y-m-d" }}T{{ last_update|time:"h:i:s" }}Z</updated>
+<author>
+    <name>Nirgal Vourgère</name>
+    <uri>https://ais.nirgal.com/</uri>
+    <email>jvourger@greenpeace.org</email>
+</author>
+
+{% for n in news %}
+<entry>
+    <id>tag:nirgal.com,2000:ais/{{ n.id }}</id>
+    <title>{{ n.title }}</title>
+    <published>{{ n.created|date:"Y-m-d" }}T{{ n.created|time:"h:i:s" }}Z</published>
+    <updated>{{ n.updated|date:"Y-m-d" }}T{{ n.updated|time:"h:i:s" }}Z</updated>
+    <content type='html'>
+        {{ n.txt|linebreaksbr|force_escape }}
+    </content>
+</entry>
+{% endfor %}
+</feed>
index ebcf297e6ab0fb84bc23b0c1d4eb0953e3deedba..df3a619e0d56b721219628af839d19c2961e5618 100644 (file)
@@ -13,7 +13,7 @@
 <h3>News</h3>
 
 {% for n in news %}
-<b>{{ n.t|date:"Y-m-d" }}</b><br>
+<b>{{ n.created|date:"Y-m-d" }}</b><br>
 {{ n.txt|linebreaksbr }}
 <br><br>
 {% endfor %}