2011-08-25 15:39:54 +02:00
|
|
|
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
|
2012-08-08 14:33:37 +02:00
|
|
|
from django.db.models import Q
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
from djeuscan.models import Package, Herd, Maintainer, VersionLog
|
2012-08-08 13:30:56 +02:00
|
|
|
from djeuscan.helpers import get_profile, get_account_packages
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
|
|
|
|
class BaseFeed(Feed):
|
|
|
|
feed_type = Atom1Feed
|
2011-08-28 10:45:46 +02:00
|
|
|
author_name = 'euscan'
|
|
|
|
item_author_name = author_name
|
|
|
|
ttl = 3600
|
2011-08-25 15:39:54 +02:00
|
|
|
|
|
|
|
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)
|
2011-08-25 15:39:54 +02:00
|
|
|
else:
|
|
|
|
txt = 'Version %s of package %s ' % (vlog.version, vlog.package)
|
|
|
|
if vlog.action == vlog.VERSION_REMOVED:
|
2011-08-28 10:45:46 +02:00
|
|
|
if not vlog.overlay:
|
2011-08-25 15:39:54 +02:00
|
|
|
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())
|
2011-08-25 15:39:54 +02:00
|
|
|
|
|
|
|
def item_pubdate(self, vlog):
|
|
|
|
return vlog.datetime
|
|
|
|
|
|
|
|
def item_categories(self, vlog):
|
|
|
|
return [vlog.package.category]
|
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def items(self, data=None):
|
|
|
|
user = data.get("user", None) if data else None
|
|
|
|
options = data.get("options", None) if data else None
|
|
|
|
|
|
|
|
upstream_info = True
|
|
|
|
portage_info = True
|
|
|
|
|
|
|
|
# first of all consider options, then user preferences
|
|
|
|
if options:
|
|
|
|
upstream_info = "upstream_info" in options
|
|
|
|
portage_info = "portage_info" in options
|
|
|
|
elif user:
|
|
|
|
profile = get_profile(user)
|
|
|
|
upstream_info = profile.upstream_info
|
|
|
|
portage_info = profile.portage_info
|
|
|
|
|
|
|
|
ret, max_items = self._items(data)
|
|
|
|
|
|
|
|
if not upstream_info:
|
|
|
|
ret = ret.exclude(overlay="")
|
|
|
|
if not portage_info:
|
|
|
|
ret = ret.exclude(~Q(overlay=""))
|
|
|
|
|
|
|
|
return ret.order_by("-datetime")[:max_items]
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
class GlobalFeed(BaseFeed):
|
|
|
|
title = "euscan"
|
|
|
|
link = "/"
|
|
|
|
description = "Last euscan changes"
|
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def get_object(self, request):
|
|
|
|
return {"options": request.GET}
|
|
|
|
|
|
|
|
def categories(self, data):
|
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]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
return VersionLog.objects.all(), 250
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
class PackageFeed(BaseFeed):
|
|
|
|
feed_type = Atom1Feed
|
|
|
|
|
|
|
|
def get_object(self, request, category, package):
|
2012-08-09 12:20:19 +02:00
|
|
|
return {
|
|
|
|
"obj": get_object_or_404(Package, category=category, name=package),
|
|
|
|
"options": request.GET,
|
|
|
|
}
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def title(self, data):
|
|
|
|
return "%s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def link(self, data):
|
|
|
|
return reverse('djeuscan.views.package', args=[data["obj"].category,
|
|
|
|
data["obj"].name])
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def description(self, data):
|
|
|
|
return data["obj"].description
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
return VersionLog.objects.for_package(data["obj"]), 30
|
2011-08-25 15:39:54 +02:00
|
|
|
|
|
|
|
def item_description(self, vlog):
|
|
|
|
return ''
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
class MaintainerFeed(BaseFeed):
|
|
|
|
feed_type = Atom1Feed
|
|
|
|
|
|
|
|
def get_object(self, request, maintainer_id):
|
2012-08-09 12:20:19 +02:00
|
|
|
return {
|
|
|
|
"obj": get_object_or_404(Maintainer, id=maintainer_id),
|
|
|
|
"options": request.GET,
|
|
|
|
}
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def title(self, data):
|
|
|
|
return "%s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def description(self, data):
|
|
|
|
return "Last changes for %s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def link(self, data):
|
2012-04-28 18:16:05 +02:00
|
|
|
return reverse('djeuscan.views.maintainer',
|
2012-08-09 12:20:19 +02:00
|
|
|
kwargs={'maintainer_id': data["obj"].id})
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
return VersionLog.objects.for_maintainer(data["obj"]), 50
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
class HerdFeed(BaseFeed):
|
|
|
|
feed_type = Atom1Feed
|
|
|
|
|
|
|
|
def get_object(self, request, herd):
|
2012-08-09 12:20:19 +02:00
|
|
|
return {
|
|
|
|
"obj": get_object_or_404(Herd, herd=herd),
|
|
|
|
"options": request.GET,
|
|
|
|
}
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def title(self, data):
|
|
|
|
return "%s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def description(self, data):
|
|
|
|
return "Last changes for %s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def link(self, data):
|
|
|
|
return reverse('djeuscan.views.herd',
|
|
|
|
kwargs={'herd': data["obj"].herd})
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
return VersionLog.objects.for_herd(data["obj"]), 100
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-25 15:39:54 +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():
|
2011-08-25 15:39:54 +02:00
|
|
|
raise FeedDoesNotExist
|
2012-08-09 12:20:19 +02:00
|
|
|
return {
|
|
|
|
"obj": category,
|
|
|
|
"options": request.GET,
|
|
|
|
}
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def title(self, data):
|
|
|
|
return "%s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def description(self, data):
|
|
|
|
return "Last changes for %s" % data["obj"]
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def link(self, data):
|
|
|
|
return reverse('djeuscan.views.category', args=[data["obj"]])
|
2011-08-25 15:39:54 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
return VersionLog.objects.for_category(data["obj"]), 100
|
2012-08-08 13:30:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UserFeed(BaseFeed):
|
|
|
|
link = "/"
|
|
|
|
|
2012-08-08 15:19:31 +02:00
|
|
|
def description(self, data):
|
2012-08-09 12:20:19 +02:00
|
|
|
return "%s - last euscan changes" % data["user"]
|
2012-08-08 13:30:56 +02:00
|
|
|
|
2012-08-08 15:19:31 +02:00
|
|
|
def title(self, data):
|
2012-08-09 12:20:19 +02:00
|
|
|
return "%s - watched packages" % data["user"]
|
2012-08-08 13:30:56 +02:00
|
|
|
|
|
|
|
def get_object(self, request):
|
2012-08-09 12:20:19 +02:00
|
|
|
return {
|
|
|
|
"user": request.user,
|
|
|
|
"options": request.GET,
|
|
|
|
}
|
2012-08-08 15:19:31 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
def _items(self, data):
|
|
|
|
user, options = data["user"], data["options"]
|
2012-08-08 13:30:56 +02:00
|
|
|
|
2012-08-08 14:33:37 +02:00
|
|
|
profile = get_profile(user)
|
2012-08-08 13:30:56 +02:00
|
|
|
packages = get_account_packages(user)
|
2012-08-08 14:33:37 +02:00
|
|
|
overlays = [o.name for o in profile.overlays.all()]
|
2012-08-08 13:30:56 +02:00
|
|
|
|
2012-08-09 12:20:19 +02:00
|
|
|
return VersionLog.objects.filter(
|
2012-08-08 14:33:37 +02:00
|
|
|
Q(package__in=packages) | Q(overlay__in=overlays)
|
2012-08-09 12:20:19 +02:00
|
|
|
), 100
|