euscan-ng/euscanwww/djeuscan/feeds.py

174 lines
4.9 KiB
Python
Raw Normal View History

from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import Atom1Feed
from django.core.urlresolvers import reverse
from django.db.models import Q
2012-04-28 18:16:05 +02:00
from djeuscan.models import Package, Herd, Maintainer, VersionLog
from djeuscan.helpers import get_profile, get_account_packages
2012-04-28 18:16:05 +02:00
class BaseFeed(Feed):
feed_type = Atom1Feed
author_name = 'euscan'
item_author_name = author_name
ttl = 3600
def item_title(self, vlog):
return str(vlog)
def item_description(self, vlog):
if vlog.overlay:
2012-04-28 18:16:05 +02:00
txt = 'Version %s-%s [%s] of package %s ' % \
(vlog.version, vlog.revision, vlog.slot, vlog.package)
else:
txt = 'Version %s of package %s ' % (vlog.version, vlog.package)
if vlog.action == vlog.VERSION_REMOVED:
if not vlog.overlay:
txt += 'has been removed upstream'
else:
txt += 'has been removed from overlay "%s"' % vlog.overlay
if vlog.action == vlog.VERSION_ADDED:
if not vlog.overlay:
txt += 'has been added upstream'
else:
txt += 'has been added to overlay "%s"' % vlog.overlay
return txt
def item_link(self, vlog):
2012-04-28 18:16:05 +02:00
kwargs = {'category': vlog.package.category,
'package': vlog.package.name}
return "%s#%s" % (reverse('djeuscan.views.package', kwargs=kwargs),
vlog.tag())
def item_pubdate(self, vlog):
return vlog.datetime
def item_categories(self, vlog):
return [vlog.package.category]
2012-04-28 18:16:05 +02:00
class GlobalFeed(BaseFeed):
title = "euscan"
link = "/"
description = "Last euscan changes"
def categories(self):
2012-05-05 10:30:09 +02:00
categories = Package.objects.categories()
2012-04-28 18:16:05 +02:00
return [category['category'] for category in categories]
def items(self):
return VersionLog.objects.order_by('-id')[:250]
2012-04-28 18:16:05 +02:00
class PackageFeed(BaseFeed):
feed_type = Atom1Feed
def get_object(self, request, category, package):
return get_object_or_404(Package, category=category, name=package)
def title(self, package):
return "%s" % package
def link(self, package):
2012-04-28 18:16:05 +02:00
return reverse('djeuscan.views.package', args=[package.category,
package.name])
def description(self, package):
return package.description
def items(self, package):
2012-05-05 11:48:12 +02:00
return VersionLog.objects.for_package(package, order=True)[:30]
def item_description(self, vlog):
return ''
2012-04-28 18:16:05 +02:00
class MaintainerFeed(BaseFeed):
feed_type = Atom1Feed
def get_object(self, request, maintainer_id):
return get_object_or_404(Maintainer, id=maintainer_id)
def title(self, maintainer):
return "%s" % maintainer
def description(self, maintainer):
return "Last changes for %s" % maintainer
def link(self, maintainer):
2012-04-28 18:16:05 +02:00
return reverse('djeuscan.views.maintainer',
kwargs={'maintainer_id': maintainer.id})
def items(self, maintainer):
2012-05-05 11:48:12 +02:00
return VersionLog.objects.for_maintainer(maintainer, order=True)[:50]
2012-04-28 18:16:05 +02:00
class HerdFeed(BaseFeed):
feed_type = Atom1Feed
def get_object(self, request, herd):
return get_object_or_404(Herd, herd=herd)
def title(self, herd):
return "%s" % herd
def description(self, herd):
return "Last changes for %s" % herd
def link(self, herd):
2012-04-28 18:16:05 +02:00
return reverse('djeuscan.views.herd', kwargs={'herd': herd.herd})
def items(self, herd):
2012-05-05 11:48:12 +02:00
return VersionLog.objects.for_herd(herd, order=True)[:100]
2012-04-28 18:16:05 +02:00
class CategoryFeed(BaseFeed):
feed_type = Atom1Feed
def get_object(self, request, category):
2012-05-05 10:30:09 +02:00
if not Package.objects.categories().count():
raise FeedDoesNotExist
return category
def title(self, category):
return "%s" % category
def description(self, category):
return "Last changes for %s" % category
def link(self, category):
return reverse('djeuscan.views.category', args=[category])
def items(self, category):
2012-05-05 11:48:12 +02:00
return VersionLog.objects.for_category(category, order=True)[:100]
class UserFeed(BaseFeed):
link = "/"
def description(self, user):
return "%s - last euscan changes"
def title(self, user):
return "%s - watched packages" % user
def get_object(self, request):
return request.user
def items(self, user):
profile = get_profile(user)
packages = get_account_packages(user)
overlays = [o.name for o in profile.overlays.all()]
ret = VersionLog.objects.filter(
Q(package__in=packages) | Q(overlay__in=overlays)
)
if not profile.upstream_info:
ret = ret.exclude(overlay="")
if not profile.portage_info:
ret = ret.exclude(~Q(overlay=""))
return ret.order_by("-datetime")[:100]