diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 01:01:30 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-15 01:01:30 -0400 |
commit | 7a8b5707b277f052b712c51574b0e28834b5a5f8 (patch) | |
tree | 18691be7e163ae7d93b812fd31fc8e51693f7bd2 /feeds.py | |
parent | 88d96927964a3c9dd1effa73b613df536aa2a0c4 (diff) | |
parent | e7449f7063f3f56af118ed8ad703ec3fce6bc39a (diff) |
Merge tag 'release_2014-10-28' into archweb-generic
Fix django_countries issues
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 66 |
1 files changed, 23 insertions, 43 deletions
@@ -1,5 +1,4 @@ from datetime import datetime, time -import hashlib from pytz import utc from django.conf import settings @@ -16,42 +15,23 @@ from releng.models import Release class BatchWritesWrapper(object): - def __init__(self, outfile, chunks=20): + def __init__(self, outfile): self.outfile = outfile - self.chunks = chunks self.buf = [] + def write(self, s): buf = self.buf buf.append(s) - if len(buf) >= self.chunks: + if len(buf) >= 40: self.outfile.write(''.join(buf)) self.buf = [] + def flush(self): self.outfile.write(''.join(self.buf)) self.outfile.flush() -class GuidNotPermalinkFeed(Rss201rev2Feed): - @staticmethod - 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 - - def write_items(self, handler): - ''' - Totally disgusting. Monkey-patch the handler 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 = self.check_for_unique_id( - handler.addQuickElement) - super(GuidNotPermalinkFeed, self).write_items(handler) - +class FasterRssFeed(Rss201rev2Feed): def write(self, outfile, encoding): ''' Batch the underlying 'write' calls on the outfile because Python's @@ -60,16 +40,10 @@ class GuidNotPermalinkFeed(Rss201rev2Feed): '>' closing tags and over 1600 write calls in our package feed. ''' wrapper = BatchWritesWrapper(outfile) - super(GuidNotPermalinkFeed, self).write(wrapper, encoding) + super(FasterRssFeed, self).write(wrapper, encoding) wrapper.flush() -def package_etag(request, *args, **kwargs): - latest = package_last_modified(request) - if latest: - return hashlib.md5(str(kwargs) + str(latest)).hexdigest() - return None - def package_last_modified(request, *args, **kwargs): cursor = connection.cursor() cursor.execute("SELECT MAX(last_update) FROM packages") @@ -77,12 +51,12 @@ def package_last_modified(request, *args, **kwargs): class PackageFeed(Feed): - feed_type = GuidNotPermalinkFeed + feed_type = FasterRssFeed link = '/packages/' def __call__(self, request, *args, **kwargs): - wrapper = condition(etag_func=package_etag, last_modified_func=package_last_modified) + wrapper = condition(last_modified_func=package_last_modified) return wrapper(super(PackageFeed, self).__call__)(request, *args, **kwargs) __name__ = 'package_feed' @@ -132,6 +106,8 @@ class PackageFeed(Feed): def items(self, obj): return obj['qs'] + item_guid_is_permalink = False + def item_guid(self, item): # http://diveintomark.org/archives/2004/05/28/howto-atom-id date = item.last_update @@ -152,12 +128,6 @@ class PackageFeed(Feed): return (item.repo.name, item.arch.name) -def news_etag(request, *args, **kwargs): - latest = news_last_modified(request) - if latest: - return hashlib.md5(str(latest)).hexdigest() - return None - def news_last_modified(request, *args, **kwargs): cursor = connection.cursor() cursor.execute("SELECT MAX(last_modified) FROM news") @@ -165,7 +135,7 @@ def news_last_modified(request, *args, **kwargs): class NewsFeed(Feed): - feed_type = GuidNotPermalinkFeed + feed_type = FasterRssFeed title = settings.BRANDING_DISTRONAME+': Recent news updates' link = '/news/' @@ -173,7 +143,7 @@ class NewsFeed(Feed): subtitle = description def __call__(self, request, *args, **kwargs): - wrapper = condition(etag_func=news_etag, last_modified_func=news_last_modified) + wrapper = condition(last_modified_func=news_last_modified) return wrapper(super(NewsFeed, self).__call__)(request, *args, **kwargs) __name__ = 'news_feed' @@ -182,12 +152,17 @@ class NewsFeed(Feed): return News.objects.select_related('author').order_by( '-postdate', '-id')[:10] + item_guid_is_permalink = False + def item_guid(self, item): return item.guid def item_pubdate(self, item): return item.postdate + def item_updateddate(self, item): + return item.last_modified + def item_author_name(self, item): return item.author.get_full_name() @@ -199,7 +174,7 @@ class NewsFeed(Feed): class ReleaseFeed(Feed): - feed_type = GuidNotPermalinkFeed + feed_type = FasterRssFeed title = settings.BRANDING_DISTRONAME+': Releases' link = '/download/' @@ -220,6 +195,11 @@ class ReleaseFeed(Feed): def item_pubdate(self, item): return datetime.combine(item.release_date, time()).replace(tzinfo=utc) + def item_updateddate(self, item): + return item.last_modified + + item_guid_is_permalink = False + def item_guid(self, item): # http://diveintomark.org/archives/2004/05/28/howto-atom-id date = item.release_date |