First try at an ATOM feed

This commit is contained in:
Tom Willemsen 2011-10-29 01:37:55 +02:00
parent d7f9943510
commit e533b3b82e
4 changed files with 48 additions and 0 deletions

View file

@ -6,4 +6,5 @@ urlpatterns = patterns('blog.views',
(r'^post/(?P<post_id>\d+)/$', 'post'), (r'^post/(?P<post_id>\d+)/$', 'post'),
(r'^tags/$', 'tags'), (r'^tags/$', 'tags'),
(r'^tag/(?P<tag_name>[\w_]+)/$', 'tag'), (r'^tag/(?P<tag_name>[\w_]+)/$', 'tag'),
(r'^atom/$', 'atom'),
) )

View file

@ -27,6 +27,14 @@ def index(request, page=0):
return direct_to_template(request, "blog/posts.html", c) return direct_to_template(request, "blog/posts.html", c)
def atom(request):
post_list = Post.objects.all().order_by("-postdate")[0:15]
c = {
'postlist': post_list,
}
return direct_to_template(request, "blog/rss.xml", c)
def post(request, post_id): def post(request, post_id):
post = Post.objects.filter(pk=post_id) post = Post.objects.filter(pk=post_id)
t = loader.get_template("blog/posts.html") t = loader.get_template("blog/posts.html")

View file

@ -3,3 +3,17 @@
{% block subtitle %} {% block subtitle %}
blog blog
{% endblock %} {% endblock %}
{% block extrastyle %}
<link href="/blog/atom/" type="application/atom+xml" rel="alternate"
title="Blog ATOM feed" />
{% endblock %}
{% block submenu %}
<div class="container">
<div class="header">
blog
</div>
<a href="/blog/atom/">feed</a>
</div>
{% endblock %}

25
templates/blog/rss.xml Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>ryuslash.org</title>
<link href="http://ryuslash.org/feed/rss/" rel="self" />
<link href="http://ryuslash.org/" />
<id>http://ryuslash.org/blog/</id>
<author>
<name>Tom Willemsen</name>
</author>
<updated>2011-10-29T23:16:00+01:00</updated>
{% for post in postlist %}
<entry>
<title>{{ post.subject }}</title>
<link href="http://ryuslash.org/blog/post/{{ post.pk }}/" />
<id>http://ryuslash.org/blog/post/{{ post.pk }}/</id>
<updated>{{ post.postdate|date:"c" }}</updated>
<content type="xhtml" xml:base="http://ryuslash.org/">
<div xmlns="http://www.w3.org/1999/xhtml">
{{ post.body|linebreaksbr }}
</div>
</content>
</entry>
{% endfor %}
</feed>