commit 0aeb704c976e6724f022261ceb5e557949ca816f
parent 5b543c4acb43f8a5dea0cb66fc88a7a398525625
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 6 Sep 2008 13:47:36 +1000
reading log at /+reading/
Diffstat:
6 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/TODO b/TODO
@@ -13,4 +13,3 @@
- pings, e.g. http://www.technorati.com/developers/ping/
- http://www.pell.portland.or.us/~orc/Code/markdown/ or http://github.com/jgm/peg-markdown/tree/master
- tag cloud at /+tags/
-- reading log at /+reading/ maybe?
diff --git a/app.py b/app.py
@@ -22,6 +22,7 @@ class Constance(RegexApplication):
urls = [(r'^$', 'index'),
(r'^feed$', 'feed'),
(r'^\+tags/(.+)$', 'tag'),
+ (r'^\+reading/?$', 'reading'),
(r'^([^+/][^/]*)/?$', 'post')]
charset = 'utf-8'
@@ -56,7 +57,7 @@ class Constance(RegexApplication):
environ=self.request.environ,
title=None,
self_url='%s/' % self.request.environ['APP_URI'],
- sorted_entries=sorted_entries[:self.config.getint('global', 'entries_per_page')],
+ sorted_entries=sorted_entries[:self.config.getint('global', 'entries_in_feed')],
feed_updated=sorted_entries[0].modified_date
).render('xml')
return HttpResponse(rendered, [('Content-Type', 'application/atom+xml')], 200)
@@ -99,7 +100,31 @@ class Constance(RegexApplication):
environ=self.request.environ,
title=u'ā%sā tag' % tag,
self_url='%s/+tags/%s' % (self.request.environ['APP_URI'], tag.encode(self.charset)),
- sorted_entries=sorted_entries[:self.config.getint('global', 'entries_per_page')],
+ sorted_entries=sorted_entries[:self.config.getint('global', 'entries_in_feed')],
+ feed_updated=sorted_entries[0].modified_date
+ ).render('xml')
+ return HttpResponse(rendered, [('Content-Type', 'application/atom+xml')], 200)
+ else:
+ raise PageNotFound('Unknown format %r' % format)
+
+ def reading(self):
+ sorted_entries = sorted(self.readinglog_entries, key=lambda e: e.publication_date, reverse=True)
+ format = self.request.args.get('format', 'html')
+ if format == 'html':
+ rendered = template_loader.load('multiple.xml').generate(
+ config=self.config,
+ environ=self.request.environ,
+ title=u'reading log',
+ sorted_entries=sorted_entries,
+ ).render('xhtml')
+ return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
+ elif format == 'atom':
+ rendered = template_loader.load('multiple_atom.xml').generate(
+ config=self.config,
+ environ=self.request.environ,
+ title=u'reading log',
+ self_url='%s/+reading/' % self.request.environ['APP_URI'],
+ sorted_entries=sorted_entries[:self.config.getint('global', 'entries_in_feed')],
feed_updated=sorted_entries[0].modified_date
).render('xml')
return HttpResponse(rendered, [('Content-Type', 'application/atom+xml')], 200)
diff --git a/config.defaults b/config.defaults
@@ -13,6 +13,9 @@ email =
# The maximum number of entries (of any kind) to be shown on each page.
entries_per_page = 20
+# The maximum number of entries to be included in feeds.
+entries_in_feed = 20
+
[blog]
# The directory containing blog entries.
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -10,7 +10,7 @@ from viewutils import mini_markdown, tag_list
<div class="entry" py:if="isinstance(entry, blog.BlogEntry)">
- <h3 class="entrytitle" id="post-${entry.id}">${mini_markdown(entry.title)}</h3>
+ <h3 class="entrytitle" id="entry-${entry.id}">${mini_markdown(entry.title)}</h3>
<div class="entrydate">
${entry.publication_date.strftime(str('%-1d %b %Y'))}
@@ -63,7 +63,7 @@ from viewutils import mini_markdown, tag_list
src="http://covers.librarything.com/devkey/${config.get('readinglog', 'librarything_devkey')}/small/isbn/${entry.isbn}"
alt="Cover image for ${entry.title}" />
- <h3 class="entrytitle" id="post-${entry.id}">
+ <h3 class="entrytitle" id="entry-${entry.id}">
<a py:strip="not entry.url" href="${entry.url}">${mini_markdown(entry.title)}</a>
<py:if test="entry.author">
<span class="author">by ${entry.author}</span>
@@ -72,6 +72,7 @@ from viewutils import mini_markdown, tag_list
<div class="entrydate">
${entry.publication_date.strftime(str('%-1d %b %Y'))}
+ <a href="${environ.get('SCRIPT_NAME', '')}/+reading/#entry-${entry.id}" rel="bookmark" class="permalink" title="permalink">#</a>
</div>
<div py:if="entry.rating" class="rating">
diff --git a/templates/multiple.xml b/templates/multiple.xml
@@ -9,14 +9,16 @@
<head>
<title py:if="title">${title}</title>
<link rel="alternate" type="application/atom+xml" title="Atom feed" href="?format=atom" />
- <link py:if="bool(offset)" rel="prev" href="?offset=${max(0, offset - 20)}" />
- <link py:if="len(sorted_entries) > offset + config.getint('global', 'entries_per_page')" rel="next" href="?offset=${offset + 20}" />
+ <py:if test="defined('offset')">
+ <link py:if="bool(offset)" rel="prev" href="?offset=${max(0, offset - 20)}" />
+ <link py:if="len(sorted_entries) > offset + config.getint('global', 'entries_per_page')" rel="next" href="?offset=${offset + 20}" />
+ </py:if>
</head>
<body>
-<h2 class="archives" py:if="title">Archive for the ${title}</h2>
+<h2 class="archives" py:if="title">Archive of ${title}</h2>
-<py:for each="entry in sorted_entries[offset:offset + config.getint('global', 'entries_per_page')]">
+<py:for each="entry in (defined('offset') and sorted_entries[offset:offset + config.getint('global', 'entries_per_page')] or sorted_entries)">
${show_entry(entry, show_comments=False)}
</py:for>
diff --git a/templates/multiple_atom.xml b/templates/multiple_atom.xml
@@ -34,6 +34,7 @@ ATOM_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
</xhtml:div></content>
</py:if>
<py:if test="isinstance(entry, blog.ReadingLogEntry)">
+ <link rel="alternate" href="${environ['APP_URI']}/+reading/#entry-${entry.id}" />
<title type="text">${entry.title} by ${entry.author}</title>
<summary py:if="entry.rating" type="text">${entry.rating} stars</summary>
<content type="xhtml"><xhtml:div>