2009-10-30 14:24:26 -07:00
|
|
|
import datetime
|
2010-02-02 20:36:41 -08:00
|
|
|
|
2010-06-08 08:52:53 -07:00
|
|
|
from django.contrib.syndication.feeds import FeedDoesNotExist
|
|
|
|
from django.contrib.syndication.views import Feed
|
2010-02-02 20:36:41 -08:00
|
|
|
from django.db.models import Q
|
2010-02-09 22:29:27 -08:00
|
|
|
from main.models import Arch, Repo, Package, News
|
2009-10-30 14:24:26 -07:00
|
|
|
|
|
|
|
class PackageFeed(Feed):
|
2010-05-04 08:02:54 -07:00
|
|
|
link = '/packages/'
|
2010-06-08 08:52:53 -07:00
|
|
|
title_template = 'feeds/packages_title.html'
|
|
|
|
description_template = 'feeds/packages_description.html'
|
2010-05-04 08:02:54 -07:00
|
|
|
|
2010-06-08 08:52:53 -07:00
|
|
|
def get_object(self, request, arch='', repo=''):
|
2010-02-02 20:36:41 -08:00
|
|
|
obj = dict()
|
|
|
|
qs = Package.objects.select_related('arch', 'repo').order_by('-last_update')
|
|
|
|
|
2010-06-08 08:52:53 -07:00
|
|
|
if arch != '':
|
2010-02-02 20:36:41 -08:00
|
|
|
# feed for a single arch, also include 'any' packages everywhere
|
2010-06-08 08:52:53 -07:00
|
|
|
a = Arch.objects.get(name=arch)
|
2010-02-02 20:36:41 -08:00
|
|
|
qs = qs.filter(Q(arch=a) | Q(arch__name__iexact='any'))
|
|
|
|
obj['arch'] = a
|
2010-06-08 08:52:53 -07:00
|
|
|
if repo != '':
|
2010-02-02 20:36:41 -08:00
|
|
|
# feed for a single arch AND repo
|
2010-06-08 08:52:53 -07:00
|
|
|
r = Repo.objects.get(name=repo)
|
2010-02-02 20:36:41 -08:00
|
|
|
qs = qs.filter(repo=r)
|
|
|
|
obj['repo'] = r
|
|
|
|
obj['qs'] = qs[:50]
|
|
|
|
return obj
|
|
|
|
|
|
|
|
def title(self, obj):
|
|
|
|
s = 'Arch Linux: Recent package updates'
|
|
|
|
if 'repo' in obj:
|
|
|
|
s += ' (%s [%s])' % (obj['arch'].name, obj['repo'].name.lower())
|
|
|
|
elif 'arch' in obj:
|
|
|
|
s += ' (%s)' % (obj['arch'].name)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def description(self, obj):
|
|
|
|
s = 'Recently updated packages in the Arch Linux package repositories'
|
|
|
|
if 'arch' in obj:
|
|
|
|
s += ' for the \'%s\' architecture' % obj['arch'].name.lower()
|
|
|
|
if obj['arch'].name != 'any':
|
|
|
|
s += ' (including \'any\' packages)'
|
|
|
|
if 'repo' in obj:
|
|
|
|
s += ' in the [%s] repository' % obj['repo'].name.lower()
|
|
|
|
s += '.'
|
|
|
|
return s
|
|
|
|
|
|
|
|
def items(self, obj):
|
|
|
|
return obj['qs']
|
2009-10-30 14:24:26 -07:00
|
|
|
|
|
|
|
def item_pubdate(self, item):
|
|
|
|
return item.last_update
|
|
|
|
|
|
|
|
def item_categories(self, item):
|
|
|
|
return (item.repo.name,item.arch.name)
|
|
|
|
|
2010-02-02 20:36:41 -08:00
|
|
|
|
2009-10-30 14:24:26 -07:00
|
|
|
class NewsFeed(Feed):
|
2010-02-02 20:36:41 -08:00
|
|
|
title = 'Arch Linux: Recent news updates'
|
|
|
|
link = '/news/'
|
2010-01-31 13:36:42 -08:00
|
|
|
description = 'The latest and greatest news from the Arch Linux distribution.'
|
2010-06-08 08:52:53 -07:00
|
|
|
title_template = 'feeds/news_title.html'
|
|
|
|
description_template = 'feeds/news_description.html'
|
2009-10-30 14:24:26 -07:00
|
|
|
|
|
|
|
def items(self):
|
2010-01-31 13:19:12 -08:00
|
|
|
return News.objects.select_related('author').order_by('-postdate', '-id')[:10]
|
2009-10-30 14:24:26 -07:00
|
|
|
|
|
|
|
def item_pubdate(self, item):
|
|
|
|
d = item.postdate
|
|
|
|
return datetime.datetime(d.year, d.month, d.day)
|
|
|
|
|
|
|
|
def item_author_name(self, item):
|
|
|
|
return item.author.get_full_name()
|
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 et:
|