From d685d51e8c80f29d4f14977a0d8088534e6626c4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 20 May 2012 13:21:59 -0500 Subject: Ensure we use last_modified date from News in headers We were actually using the postdate attribute rather than last_modified, which means any News objects that get edited would not trigger an update of the feed. Signed-off-by: Dan McGee --- feeds.py | 4 ++-- main/utils.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/feeds.py b/feeds.py index ee856f62..2e9b349b 100644 --- a/feeds.py +++ b/feeds.py @@ -106,13 +106,13 @@ def item_categories(self, item): def news_etag(request, *args, **kwargs): - latest = retrieve_latest(News) + latest = retrieve_latest(News, 'last_modified') if latest: return hashlib.md5(str(latest)).hexdigest() return None def news_last_modified(request, *args, **kwargs): - return retrieve_latest(News) + return retrieve_latest(News, 'last_modified') class NewsFeed(Feed): feed_type = GuidNotPermalinkFeed diff --git a/main/utils.py b/main/utils.py index e7e47c53..b7cb19f4 100644 --- a/main/utils.py +++ b/main/utils.py @@ -72,7 +72,7 @@ def refresh_latest(**kwargs): cache.set(cache_key, None, INVALIDATE_TIMEOUT) -def retrieve_latest(sender): +def retrieve_latest(sender, latest_by=None): # we could break this down based on the request url, but it would probably # cost us more in query time to do so. cache_key = CACHE_LATEST_PREFIX + sender.__name__ @@ -80,8 +80,9 @@ def retrieve_latest(sender): if latest: return latest try: - latest_by = sender._meta.get_latest_by - latest = sender.objects.values(latest_by).latest()[latest_by] + if latest_by is None: + latest_by = sender._meta.get_latest_by + latest = sender.objects.values(latest_by).latest(latest_by)[latest_by] # Using add means "don't overwrite anything in there". What could be in # there is an explicit None value that our refresh signal set, which # means we want to avoid race condition possibilities for a bit. -- cgit v1.2.3-54-g00ecf