From 0d3e1eb796d673607bb8beb91c61114209fd9155 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 7 Apr 2011 15:07:37 -0500 Subject: Add a horrible hack to allow feed guid value to not be a permalink Django, you make the simplest things so damn hard sometimes. Signed-off-by: Dan McGee --- feeds.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'feeds.py') diff --git a/feeds.py b/feeds.py index d2043271..7a2f2e40 100644 --- a/feeds.py +++ b/feeds.py @@ -5,6 +5,7 @@ from django.contrib.sites.models import Site from django.contrib.syndication.views import Feed from django.core.cache import cache from django.db.models import Q +from django.utils.feedgenerator import Rss201rev2Feed from django.utils.hashcompat import md5_constructor from django.views.decorators.http import condition @@ -13,6 +14,24 @@ from main.utils import CACHE_TIMEOUT, INVALIDATE_TIMEOUT from main.utils import CACHE_PACKAGE_KEY, CACHE_NEWS_KEY from news.models import News +def check_for_unique_id(f): + def wrapper(name, contents=None, attrs=None): + if attrs is None: + attrs = {} + if name == 'guid': + attrs['isPermaLink'] = 'false' + return f(name, contents, attrs) + return wrapper + +class GuidNotPermalinkFeed(Rss201rev2Feed): + def write_items(self, handler): + # Totally disgusting. Monkey-patch the hander so if it sees a + # 'unique-id' field come through, add an isPermalink="false" attribute. + # Workaround for http://code.djangoproject.com/ticket/9800 + handler.addQuickElement = check_for_unique_id(handler.addQuickElement) + super(GuidNotPermalinkFeed, self).write_items(handler) + + def utc_offset(): '''Calculate the UTC offset from local time. Useful for converting values stored in local time to things like cache last modifed headers.''' @@ -53,6 +72,8 @@ def package_last_modified(request, *args, **kwargs): return retrieve_package_latest() class PackageFeed(Feed): + feed_type = GuidNotPermalinkFeed + link = '/packages/' title_template = 'feeds/packages_title.html' description_template = 'feeds/packages_description.html' @@ -142,6 +163,8 @@ def news_last_modified(request, *args, **kwargs): return retrieve_news_latest() class NewsFeed(Feed): + feed_type = GuidNotPermalinkFeed + title = 'Arch Linux: Recent news updates' link = '/news/' description = 'The latest and greatest news from the Arch Linux distribution.' -- cgit v1.2.3-55-g3dc8