diff options
author | Dan McGee <dan@archlinux.org> | 2011-04-07 15:07:37 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-04-07 17:01:31 -0500 |
commit | 0d3e1eb796d673607bb8beb91c61114209fd9155 (patch) | |
tree | be27970e381f993780fdffd93dce851b7613b468 /feeds.py | |
parent | 9f4902f9c921b82f924fe0af106fa5480ca10ca9 (diff) |
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 <dan@archlinux.org>
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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.' |