Mercurial > hg > bitsyblog
changeset 84:e5a23f5ea14e
make cooked bodies depend on file mtime
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 17 Nov 2011 13:18:51 -0800 |
parents | 666f3051ce31 |
children | f7c6fbce7c9b |
files | bitsyblog/bitsyblog.py bitsyblog/blog.py bitsyblog/utils.py |
diffstat | 3 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py Thu Nov 17 12:15:43 2011 -0800 +++ b/bitsyblog/bitsyblog.py Thu Nov 17 13:18:51 2011 -0800 @@ -611,8 +611,12 @@ def cooked_entry(self, entry): """cook the entry""" if (entry.user, entry.datestamp()) not in self.cooked_bodies: - self.cooked_bodies[(entry.user, entry.datestamp())] = self.cooker(entry.body) - return self.cooked_bodies[(entry.user, entry.datestamp())] + self.cooked_bodies[(entry.user, entry.datestamp())] = (self.cooker(entry.body), entry.modified()) + body, modified = self.cooked_bodies[(entry.user, entry.datestamp())] + if entry.modified() > modified: + body = self.cooker(entry.body) + self.cooked_bodies[(entry.user, entry.datestamp())] = (body, entry.modified()) + return body def write_blog(self, user, blog, path, n_links, request): """return the user's blog in HTML"""
--- a/bitsyblog/blog.py Thu Nov 17 12:15:43 2011 -0800 +++ b/bitsyblog/blog.py Thu Nov 17 13:18:51 2011 -0800 @@ -1,5 +1,6 @@ """blog interfaces to data for bitsy""" +import datetime import os import utils @@ -9,10 +10,11 @@ class BlogEntry(object): """interface class for a blog entry""" - def __init__(self, date, body, privacy, user): + def __init__(self, date, body, privacy, user, modified=None): self.date = date self.body = body self.privacy = privacy + self._modified = modified if user is not None: self.user = user @@ -49,6 +51,11 @@ def datestamp(self): return utils.datestamp(self.date) + def modified(self): + """returns the last modification date""" + return self._modified or self.datestamp() + + class Blog(object): """abstract class for a users' blog""" @@ -102,19 +109,20 @@ return file(self.location(user, permission, datestamp)).read() def get_entry(self, user, datestamp, permission): - return BlogEntry(utils.date(datestamp), + modified = datetime.datetime.fromtimestamp(os.path.getmtime(self.location(user, permission, datestamp))) + return BlogEntry(utils.date(datestamp), self.body(user, datestamp, permission), - permission, user) + permission, user, modified=modified) ### interfaces from Blog - def blog(self, user, permissions, number=None): + def blog(self, user, permissions, number=None): entries = [] for permission in permissions: - entries.extend([ (entry, permission) + entries.extend([(entry, permission) for entry in os.listdir(self.location(user, permission)) ]) entries.sort(key=lambda x: x[0], reverse=True) - + if number is not None: entries = entries[:number] @@ -144,8 +152,8 @@ # get the blog entries entries = [] for permission in permissions: - entries.extend([ (os.path.split(entry)[-1], permission) - for entry in glob(os.path.join(self.location(user, permission), glob_expr)) ]) + entries.extend([(os.path.split(entry)[-1], permission) + for entry in glob(os.path.join(self.location(user, permission), glob_expr))]) entries.sort(key=lambda x: x[0], reverse=True) return [ self.get_entry(user, x[0], x[1]) for x in entries ]
--- a/bitsyblog/utils.py Thu Nov 17 12:15:43 2011 -0800 +++ b/bitsyblog/utils.py Thu Nov 17 13:18:51 2011 -0800 @@ -17,11 +17,10 @@ def ReST2html(string): """renders a string with restructured text""" - + settings = { 'report_level': 5 } string = string.strip() try: - parts = docutils.core.publish_parts(string, writer_name='html', settings_overrides=settings) @@ -32,7 +31,7 @@ return body def validate_css(css): - """use a webservice to determine if the argument is valid css""" + """use a webservice to determine if the argument is valid css""" url = 'http://jigsaw.w3.org/css-validator/validator?text=%s' url = url % urllib.quote_plus(css) foo = urllib2.urlopen(url) @@ -48,6 +47,8 @@ return datetime.datetime(*retval) def datestamp(date=None): + if isinstance(date, float): + date = datetime.datetime.fromtimestamp(date) if date is None: date = datetime.datetime.now() return date.strftime(timestamp)