Mercurial > hg > bitsyblog
changeset 79:4df927b0d847
fix unicode error in titles (i hope)
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 23 Oct 2010 16:54:36 -0700 |
parents | 5b1259424c51 |
children | 51b49bc484ff |
files | bitsyblog/bitsyblog.py bitsyblog/blog.py bitsyblog/utils.py |
diffstat | 3 files changed, 20 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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:
--- 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