# HG changeset patch # User k0s # Date 1267205245 18000 # Node ID 451169e5193534596decf6e6113f1ec00a88fdff # Parent f02a3672254e6beea1051a5495ac86924eb167e8 work to make cache expiry work diff -r f02a3672254e -r 451169e51935 commentator/middleware.py --- 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 diff -r f02a3672254e -r 451169e51935 commentator/model.py --- 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) diff -r f02a3672254e -r 451169e51935 setup.py --- a/setup.py Fri Feb 26 11:12:37 2010 -0500 +++ b/setup.py Fri Feb 26 12:27:25 2010 -0500 @@ -5,7 +5,7 @@ except IOError: description = '' -version = "0.2.1" +version = "0.2.2" setup(name='commentator', version=version,