Mercurial > hg > commentator
changeset 5:451169e51935
work to make cache expiry work
author | k0s <k0scist@gmail.com> |
---|---|
date | Fri, 26 Feb 2010 12:27:25 -0500 |
parents | f02a3672254e |
children | c95f1dfed329 |
files | commentator/middleware.py commentator/model.py setup.py |
diffstat | 3 files changed, 22 insertions(+), 11 deletions(-) [+] |
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
--- a/commentator/model.py Fri Feb 26 11:12:37 2010 -0500 +++ b/commentator/model.py Fri Feb 26 12:27:25 2010 -0500 @@ -6,9 +6,9 @@ # need a timezone object, which python *should* # have by default try: - from webob import _UTC + from webob import _UTC # XXX except ImportError: - from webob.datetime_utils import _UTC + from webob.datetime_utils import UTC class PickleComments(object): # TODO: locking @@ -21,10 +21,7 @@ def comment(self, uri, **kw): now = datetime.utcnow() - now.replace(tzinfo=_UTC()) - - # tzinfo crap -# now = datetime(*list(now.utctimetuple()[:-1]) + [_UTC()]) + now.replace(tzinfo=UTC) kw['date'] = now f = file(self.database)