Permalink
Browse files

stop using django feedgenerator

  • Loading branch information...
Benjamin Golub
Benjamin Golub committed Mar 10, 2010
1 parent 45b0660 commit eee3f6056a80dd810a1931213ef9ba72b4f70301
Showing with 38 additions and 20 deletions.
  1. +13 −20 blog.py
  2. +25 −0 templates/feed.html
View
33 blog.py
@@ -9,8 +9,6 @@
import uuid
import wsgiref.handlers
from django.utils import feedgenerator
from google.appengine.ext import db
from google.appengine.api import urlfetch
from google.appengine.api import users
@@ -63,26 +61,9 @@ def render_string(self, template_name, **kwargs):
def render(self, template_name, **kwargs):
format = self.get_argument("format", None)
if "entries" in kwargs and format == "atom":
feed = feedgenerator.Atom1Feed(
title=self.application.settings["blog_title"],
description=self.application.settings["blog_title"],
link=self.request.path,
language="en",
)
for entry in kwargs["entries"]:
feed.add_item(
title=entry.title,
link="http://" + self.request.host + "/e/" + entry.slug,
description=entry.body,
author_name=entry.author.nickname(),
pubdate=entry.published,
categories=entry.tags,
)
data = feed.writeString("utf-8")
self.set_header("Content-Type", "application/atom+xml")
self.set_sup_header()
self.write(data)
return
template_name = "feed.html"
return tornado.web.RequestHandler.render(self, template_name, **kwargs)
def slugify(self, value):
@@ -125,6 +106,18 @@ def ping(self):
urlfetch.fetch("http://www.feedburner.com/fb/a/pingSubmit?" + args)
except:
pass
args = urllib.urlencode({
"hub.mode": "publish",
"hub.url": feed,
})
headers = {
"Content-Type": "application/x-www-form-urlencoded",
}
try:
result = urlfetch.fetch("http://pubsubhubbub.appspot.com/",
payload=args, method=urlfetch.POST, headers=headers)
except:
pass
def get_error_html(self, status_code, **kwargs):
if status_code == 404:
View
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
{% set date_format = "%Y-%m-%dT%H:%M:%SZ" %}
{% set title = handler.application.settings["blog_title"] %}
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title type="text">{{ escape(title) }}</title>
<id>{{ escape(handler.request.full_url()) }}</id>
<updated>{{ max(e.updated for e in entries).strftime(date_format) }}</updated>
<link rel="alternate" href="http://{{ handler.request.host + handler.request.path }}" title="{{ escape(title) }}" type="text/html"/>
<link rel="self" href="http://{{ handler.request.host + handler.request.path }}?format=atom" title="{{ escape(title) }}" type="application/atom+xml"/>
<link rel="hub" href="http://pubsubhubbub.appspot.com/"/>
{% for entry in entries %}
<entry>
<id>tag:www.benjamingolub.com,{{ entry.published.strftime("%Y-%m-%d") }}:/e/{{ entry.slug }}</id>
<link href="http://{{ handler.request.host + "/e/" + entry.slug }}" rel="alternate" type="text/html"/>
<title type="text">{{ escape(entry.title) }}</title>
<updated>{{ entry.updated.strftime(date_format) }}</updated>
<published>{{ entry.published.strftime(date_format) }}</published>
<author><name>{{ escape(entry.author.nickname()) }}</name></author>
<content type="html">{{ escape(entry.body) }}</content>
{% for tag in entry.tags %}
<category term="{{ escape(tag) }}"></category>
{% end %}
</entry>
{% end %}
</feed>

0 comments on commit eee3f60

Please sign in to comment.