Mercurial > hg > commentator
diff commentator/middleware.py @ 5:451169e51935
work to make cache expiry work
author | k0s <k0scist@gmail.com> |
---|---|
date | Fri, 26 Feb 2010 12:27:25 -0500 |
parents | d0d8524d9495 |
children |
line wrap: on
line diff
--- a/commentator/middleware.py Fri Feb 26 11:12:37 2010 -0500 +++ b/commentator/middleware.py Fri Feb 26 12:27:25 2010 -0500 @@ -5,6 +5,7 @@ import os import re +import time from handlers import PostComment #from model import CouchComments @@ -73,7 +74,7 @@ path = [] request.environ['path'] = path - # save the path; not sure why i need to do this + # XXX save the path; not sure why i need to do this environ['commentator.path_info'] = request.path_info # match the request to a handler @@ -98,7 +99,9 @@ for index, value in enumerate(url_match.groups())]) last_modified = None + commentable = False for element in tree.findall(self.xpath_pattern): + commentable = True # get url str_dict = groups_dict.copy() @@ -110,7 +113,11 @@ data = {} data['comments'] = self.model.comments(uri) if data['comments']: - last_modified = data['comments'][-1]['date'] + _last_modified = data['comments'][-1]['date'] + if last_modified is None: + last_modified = _last_modified + else: + last_modified = max(last_modified, _last_modified) data['action'] = '%s/%s' % (uri, self.url) data['date_format'] = self.date_format data['request'] = request @@ -121,6 +128,13 @@ comments = etree.fromstring(comments) element.append(comments) - if last_modified: - import pdb; pdb.set_trace() + if commentable: + response.cache_expires(0) + + if last_modified: # there are comments + page_age = time.mktime(response.last_modified.timetuple()) + comments_age = time.mktime(last_modified.timetuple()) + if comments_age > page_age: + response.last_modified = comments_age + return tree