commit 817cd2b348d60c4b5ff3c5bba65864620f1bc627
parent d4e3194e032790c0a70d2c277c0229f6f8490978
Author: Dan Callaghan <djc@djc.id.au>
Date: Sun, 8 Jun 2008 15:30:33 +1000
moved config stuff into a separate module
committer: Dan Callaghan <djc@djc.id.au>
--HG--
extra : convert_revision : 5784a064b176fb85da94edc21172e42579c65426
Diffstat:
7 files changed, 48 insertions(+), 39 deletions(-)
diff --git a/app.py b/app.py
@@ -7,13 +7,9 @@ from colubrid import RegexApplication, HttpResponse, execute
from colubrid.exceptions import PageNotFound, HttpFound
from colubrid.server import StaticExports
+import config
import blog
-ENTRIES_DIR = os.path.join(os.path.dirname(__file__), u'entries')
-READINGLOG_FILE = os.path.join(os.path.dirname(__file__), u'reading_log')
-BASE_URL = ''
-ENTRIES_PER_PAGE = 20
-
template_loader = TemplateLoader(
os.path.join(os.path.dirname(__file__), 'templates'),
variable_lookup='strict',
@@ -30,11 +26,11 @@ class BlogApplication(RegexApplication):
def __init__(self, *args, **kwargs):
super(BlogApplication, self).__init__(*args, **kwargs)
- self.entries = blog.Entries(ENTRIES_DIR, READINGLOG_FILE)
+ self.entries = blog.Entries(config.ENTRIES_DIR, config.READINGLOG_FILE)
def index(self):
offset = int(self.request.args.get('offset', 0))
- sorted_entries = sorted(self.entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + ENTRIES_PER_PAGE]
+ sorted_entries = sorted(self.entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + config.ENTRIES_PER_PAGE]
format = self.request.args.get('format', 'html')
if format == 'html':
rendered = template_loader.load('multiple.xml').generate(
@@ -72,7 +68,7 @@ class BlogApplication(RegexApplication):
raise PageNotFound()
offset = int(self.request.args.get('offset', 0))
entries = categories[category]
- sorted_entries = sorted(entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + ENTRIES_PER_PAGE]
+ sorted_entries = sorted(entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + config.ENTRIES_PER_PAGE]
rendered = template_loader.load('multiple.xml').generate(
title=u'%s category' % category,
all_categories=self.entries.categories(),
@@ -88,7 +84,7 @@ class BlogApplication(RegexApplication):
raise PageNotFound()
offset = int(self.request.args.get('offset', 0))
entries = by_tag[tag]
- sorted_entries = sorted(entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + ENTRIES_PER_PAGE]
+ sorted_entries = sorted(entries, key=lambda e: e.publication_date, reverse=True)[offset:offset + config.ENTRIES_PER_PAGE]
rendered = template_loader.load('multiple.xml').generate(
title=u'“%s” tag' % tag,
all_categories=self.entries.categories(),
diff --git a/blog.py b/blog.py
@@ -5,6 +5,8 @@ import markdown
import genshi
import yaml
+import config
+
def count(iterable):
count = 0
@@ -134,7 +136,7 @@ class Entry(object):
os.access(self.comments_dir, os.R_OK)
def guid(self):
- return self._guid or u'http://www.djc.id.au%s/%s' % (BASE_URL, self.id)
+ return self._guid or u'%s/%s' % (config.ABSOLUTE_BASE_URL, self.id)
class ReadingLogEntry(object):
@@ -154,7 +156,7 @@ class ReadingLogEntry(object):
return False
def guid(self):
- return self._guid or u'http://www.djc.id.au%s/#post-%s' % (BASE_URL, self.id)
+ return self._guid or u'%s/#post-%s' % (config.ABSOLUTE_BASE_URL, self.id)
class Comments(object):
@@ -201,6 +203,3 @@ class Comment(object):
def author_name(self):
return self.author or u'Anonymous'
-
-
-from app import BASE_URL # XXX
diff --git a/config.py b/config.py
@@ -0,0 +1,13 @@
+
+# vim:encoding=utf-8
+
+import os
+
+ENTRIES_DIR = os.path.join(os.path.dirname(__file__), u'entries')
+READINGLOG_FILE = os.path.join(os.path.dirname(__file__), u'reading_log')
+RELATIVE_BASE_URL = ''
+ABSOLUTE_BASE_URL = 'http://www.djc.id.au%s' % RELATIVE_BASE_URL
+BLOG_NAME = u'djc'
+BLOG_AUTHOR = u'djc'
+BLOG_EMAIL = None
+ENTRIES_PER_PAGE = 20
diff --git a/templates/_commonwrapper.xml b/templates/_commonwrapper.xml
@@ -5,7 +5,7 @@
py:strip="True">
<?python
-from app import BASE_URL
+import config
?>
<py:match path="head">
@@ -15,7 +15,7 @@ from app import BASE_URL
<title py:if="not title">djc</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="generator" content="Dan’s blogging engine" />
- <link rel="stylesheet" type="text/css" href="${BASE_URL}/static/css/common.css" />
+ <link rel="stylesheet" type="text/css" href="${config.RELATIVE_BASE_URL}/static/css/common.css" />
<link rel="alternate" type="application/atom+xml" title="Atom feed" href="?format=atom" />
</head>
</py:match>
@@ -25,20 +25,20 @@ from app import BASE_URL
<div id="leftwrap">
<div class="navwidth">
<ul class="navigation">
- <li class="current_page_item"><a href="${BASE_URL}/">djc</a></li>
+ <li class="current_page_item"><a href="${config.RELATIVE_BASE_URL}/">djc</a></li>
</ul>
</div>
<div id="sidebar"><ul>
<li id="feeds">
<h2>Feeds</h2>
<ul id="feed">
- <li><a rel="alternate" type="application/atom+xml" href="${BASE_URL}/?format=atom" title="Atom feed for posts">Atom posts</a></li>
+ <li><a rel="alternate" type="application/atom+xml" href="${config.RELATIVE_BASE_URL}/?format=atom" title="Atom feed for posts">Atom posts</a></li>
</ul>
</li>
<li class="categories">
<h2>Categories</h2>
<ul>
- <li py:for="category in all_categories" class="cat-item"><a href="${BASE_URL}/+categories/${category}">${category}</a></li>
+ <li py:for="category in all_categories" class="cat-item"><a href="${config.RELATIVE_BASE_URL}/+categories/${category}">${category}</a></li>
</ul>
</li>
<li id="archives">
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -10,7 +10,7 @@ from viewutils import mini_markdown, tag_list, category_list
<div class="entry" py:if="'Reading' not in entry.categories">
- <h3 class="entrytitle" id="post-${entry.id}"><a href="${BASE_URL}/${entry.id}" rel="bookmark">${mini_markdown(entry.title)}</a></h3>
+ <h3 class="entrytitle" id="post-${entry.id}"><a href="${config.RELATIVE_BASE_URL}/${entry.id}" rel="bookmark">${mini_markdown(entry.title)}</a></h3>
<div class="entrymeta">
Posted ${entry.publication_date.strftime(str('%-1d %B %Y'))}
@@ -19,7 +19,7 @@ from viewutils import mini_markdown, tag_list, category_list
</py:if>
<py:if test="not show_comments and entry.has_comments()">
·
- <a href="${BASE_URL}/${entry.id}#comments">
+ <a href="${config.RELATIVE_BASE_URL}/${entry.id}#comments">
Comments
<py:if test="len(entry.comments()) > 0">(${len(entry.comments())})</py:if>
</a>
@@ -29,7 +29,7 @@ from viewutils import mini_markdown, tag_list, category_list
<div class="entrybody">
${entry.body}
<p py:if="entry.tags">
- <img src="${BASE_URL}/static/images/tag_blue.png" alt="Tags:" />
+ <img src="${config.RELATIVE_BASE_URL}/static/images/tag_blue.png" alt="Tags:" />
${tag_list(entry.tags)}
</p>
</div>
@@ -37,8 +37,8 @@ from viewutils import mini_markdown, tag_list, category_list
</div>
<span py:def="stars(rating)" py:strip="True">
- <img src="${BASE_URL}/static/images/star.png" alt="[star]" py:for="_ in range(int(rating))" />
- <img src="${BASE_URL}/static/images/halfstar.png" alt="[half-star]" py:if="rating > int(rating)" />
+ <img src="${config.RELATIVE_BASE_URL}/static/images/star.png" alt="[star]" py:for="_ in range(int(rating))" />
+ <img src="${config.RELATIVE_BASE_URL}/static/images/halfstar.png" alt="[half-star]" py:if="rating > int(rating)" />
</span>
<div class="entry readinglog" py:if="'Reading' in entry.categories">
@@ -51,7 +51,7 @@ from viewutils import mini_markdown, tag_list, category_list
<div class="entrymeta">
Posted ${entry.publication_date.strftime(str('%-1d %B %Y'))}
<py:if test="entry.categories">
- in <a py:for="category in entry.categories" href="${BASE_URL}/+categories/${category}">${category}</a>
+ in <a py:for="category in entry.categories" href="${config.RELATIVE_BASE_URL}/+categories/${category}">${category}</a>
</py:if>
<py:if test="entry.rating">
· ${stars(entry.rating)}
diff --git a/templates/multiple_atom.xml b/templates/multiple_atom.xml
@@ -4,15 +4,15 @@
xmlns:xi="http://www.w3.org/2001/XInclude">
<?python
-from app import BASE_URL
+import config
from viewutils import tag_list
ATOM_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
?>
-<id>http://www.djc.id.au${BASE_URL}/?format=atom</id>
-<title type="text">djc</title>
-<link rel="self" type="application/atom+xml" href="http://www.djc.id.au${BASE_URL}/?format=atom" />
-<link rel="alternate" href="http://www.djc.id.au${BASE_URL}/" />
+<id>${config.ABSOLUTE_BASE_URL}/?format=atom</id>
+<title type="text">${config.BLOG_NAME}</title>
+<link rel="self" type="application/atom+xml" href="${config.ABSOLUTE_BASE_URL}/?format=atom" />
+<link rel="alternate" href="${config.ABSOLUTE_BASE_URL}/" />
<generator>Dan’s blogging engine</generator>
<updated>${feed_updated.strftime(ATOM_TIME_FORMAT)}</updated>
@@ -21,17 +21,18 @@ ATOM_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
<published>${entry.publication_date.strftime(ATOM_TIME_FORMAT)}</published>
<updated>${entry.modified_date.strftime(ATOM_TIME_FORMAT)}</updated>
<author>
- <name>djc</name>
+ <name>${config.BLOG_AUTHOR}</name>
+ <email py:if="config.BLOG_EMAIL">${config.BLOG_EMAIL}</email>
</author>
- <category py:for="category in entry.categories" scheme="http://www.djc.id.au${BASE_URL}/+categories/" term="${category}" />
- <category py:for="tag in entry.tags" scheme="http://www.djc.id.au${BASE_URL}/+tags/" term="${tag}" />
+ <category py:for="category in entry.categories" scheme="${config.ABSOLUTE_BASE_URL}/+categories/" term="${category}" />
+ <category py:for="tag in entry.tags" scheme="${config.ABSOLUTE_BASE_URL}/+tags/" term="${tag}" />
<py:if test="'Reading' not in entry.categories">
- <link rel="alternate" href="http://www.djc.id.au${BASE_URL}/${entry.id}" />
+ <link rel="alternate" href="${config.ABSOLUTE_BASE_URL}/${entry.id}" />
<title type="text">${entry.title}</title>
- <content type="xhtml" xml:base="http://www.djc.id.au${BASE_URL}/${entry.id}"><xhtml:div>
+ <content type="xhtml" xml:base="${config.ABSOLUTE_BASE_URL}/${entry.id}"><xhtml:div>
${entry.body}
<p py:if="entry.tags">
- <img src="${BASE_URL}/static/images/tag_blue.png" alt="Tags:" />
+ <img src="${config.ABSOLUTE_BASE_URL}/static/images/tag_blue.png" alt="Tags:" />
${tag_list(entry.tags)}
</p>
</xhtml:div></content>
diff --git a/viewutils.py b/viewutils.py
@@ -2,7 +2,7 @@ import re
import markdown
import genshi
-from app import BASE_URL
+import config
def mini_markdown(s):
# XXX find a more efficient way to do this?
@@ -12,10 +12,10 @@ def mini_markdown(s):
def category_list(categories):
return genshi.Markup(u', ').join(
- genshi.Markup(u'<a href="%s/+categories/%s">%s</a>' % (BASE_URL, category, category))
+ genshi.Markup(u'<a href="%s/+categories/%s">%s</a>' % (config.RELATIVE_BASE_URL, category, category))
for category in categories)
def tag_list(tags):
return genshi.Markup(u', ').join(
- genshi.Markup(u'<a rel="tag" href="%s/+tags/%s">%s</a>' % (BASE_URL, tag, tag))
+ genshi.Markup(u'<a rel="tag" href="%s/+tags/%s">%s</a>' % (config.RELATIVE_BASE_URL, tag, tag))
for tag in tags)