# HG changeset patch # User Jeff Hammel # Date 1287878076 25200 # Node ID 4df927b0d847ed7943494f2def108a8ca93e2cb9 # Parent 5b1259424c51380c5172e8902b62b45867c00b9f fix unicode error in titles (i hope) diff -r 5b1259424c51 -r 4df927b0d847 bitsyblog/bitsyblog.py --- a/bitsyblog/bitsyblog.py Mon Sep 27 21:08:04 2010 -0700 +++ b/bitsyblog/bitsyblog.py Sat Oct 23 16:54:36 2010 -0700 @@ -642,8 +642,12 @@ # render the template template = self.loader.load('blog.html') - return template.generate(**data).render() - + try: + return template.generate(**data).render() + except UnicodeDecodeError: + # TODO: better error handling + raise + def text_blog(self, blog): if len(blog) == 1: diff -r 5b1259424c51 -r 4df927b0d847 bitsyblog/blog.py --- a/bitsyblog/blog.py Mon Sep 27 21:08:04 2010 -0700 +++ b/bitsyblog/blog.py Sat Oct 23 16:54:36 2010 -0700 @@ -17,13 +17,18 @@ self.user = user def title(self, characters=80): + if '\n' in self.body: lines = [i.strip() for i in self.body[:characters].split('\n')] if len(lines[0]) > characters: - return self.snippet(charachters) - if len(lines) > 1 and not lines[1]: - return lines[0] - return self.snippet(characters) + retval = self.snippet(charachters) + elif len(lines) > 1 and not lines[1]: + retval = lines[0] + else: + retval = self.snippet(characters) + else: + retval = self.snippet(characters) + return retval.decode('utf-8') def snippet(self, characters=80): if characters: diff -r 5b1259424c51 -r 4df927b0d847 bitsyblog/utils.py --- a/bitsyblog/utils.py Mon Sep 27 21:08:04 2010 -0700 +++ b/bitsyblog/utils.py Sat Oct 23 16:54:36 2010 -0700 @@ -6,6 +6,11 @@ import urllib import urllib2 +import docutils +import docutils.core + +from docutils.utils import SystemMessage + # format to uniquely label blog posts timeformat = ( 'YYYY', 'MM', 'DD', 'HH', 'MM', 'SS' ) timestamp = '%Y%m%d%H%M%S' # strftime representation