diff options
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 87 |
1 files changed, 70 insertions, 17 deletions
@@ -1,5 +1,6 @@ +from datetime import datetime, time import hashlib -import pytz +from pytz import utc from django.conf import settings from django.contrib.sites.models import Site @@ -11,22 +12,26 @@ from django.views.decorators.http import condition from main.utils import retrieve_latest from main.models import Arch, Repo, Package from news.models import News +from releng.models import Release -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): + @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 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) + handler.addQuickElement = self.check_for_unique_id( + handler.addQuickElement) super(GuidNotPermalinkFeed, self).write_items(handler) @@ -39,6 +44,7 @@ def package_etag(request, *args, **kwargs): def package_last_modified(request, *args, **kwargs): return retrieve_latest(Package) + class PackageFeed(Feed): feed_type = GuidNotPermalinkFeed @@ -50,10 +56,11 @@ class PackageFeed(Feed): wrapper = condition(etag_func=package_etag, last_modified_func=package_last_modified) return wrapper(super(PackageFeed, self).__call__)(request, *args, **kwargs) + __name__ = 'package_feed' + def get_object(self, request, arch='', repo=''): obj = dict() - qs = Package.objects.normal().order_by( - '-last_update') + qs = Package.objects.normal().order_by('-last_update') if arch != '': # feed for a single arch, also include 'any' packages everywhere @@ -65,13 +72,17 @@ class PackageFeed(Feed): r = Repo.objects.get(name__iexact=repo) qs = qs.filter(repo=r) obj['repo'] = r + else: + qs = qs.filter(repo__staging=False) obj['qs'] = qs[:50] return obj def title(self, obj): s = settings.BRANDING_DISTRONAME+': Recent package updates' - if 'repo' in obj: + if 'repo' in obj and 'arch' in obj: s += ' (%s [%s])' % (obj['arch'].name, obj['repo'].name.lower()) + elif 'repo' in obj: + s += ' [%s]' % (obj['repo'].name.lower()) elif 'arch' in obj: s += ' (%s)' % (obj['arch'].name) return s @@ -100,20 +111,21 @@ class PackageFeed(Feed): date.strftime('%Y%m%d%H%M')) def item_pubdate(self, item): - return item.last_update.replace(tzinfo=pytz.utc) + return item.last_update def item_categories(self, item): return (item.repo.name, item.arch.name) 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 @@ -129,6 +141,8 @@ class NewsFeed(Feed): wrapper = condition(etag_func=news_etag, last_modified_func=news_last_modified) return wrapper(super(NewsFeed, self).__call__)(request, *args, **kwargs) + __name__ = 'news_feed' + def items(self): return News.objects.select_related('author').order_by( '-postdate', '-id')[:10] @@ -137,9 +151,48 @@ class NewsFeed(Feed): return item.guid def item_pubdate(self, item): - return item.postdate.replace(tzinfo=pytz.utc) + return item.postdate def item_author_name(self, item): return item.author.get_full_name() + +class ReleaseFeed(Feed): + feed_type = GuidNotPermalinkFeed + + title = 'Arch Linux: Releases' + link = '/download/' + description = 'Release ISOs' + subtitle = description + + __name__ = 'release_feed' + + def items(self): + return Release.objects.filter(available=True)[:10] + + def item_title(self, item): + return item.version + + def item_description(self, item): + return item.info_html() + + def item_pubdate(self, item): + return datetime.combine(item.release_date, time()).replace(tzinfo=utc) + + def item_guid(self, item): + # http://diveintomark.org/archives/2004/05/28/howto-atom-id + date = item.release_date + return 'tag:%s,%s:%s' % (Site.objects.get_current().domain, + date.strftime('%Y-%m-%d'), item.get_absolute_url()) + + def item_enclosure_url(self, item): + domain = Site.objects.get_current().domain + proto = 'https' + return "%s://%s/%s.torrent" % (proto, domain, item.iso_url()) + + def item_enclosure_length(self, item): + return item.file_size or "" + + item_enclosure_mime_type = 'application/x-bittorrent' + # vim: set ts=4 sw=4 et: |