euscanwww: Changed all feeds to support url options

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-08-09 12:20:19 +02:00
parent 8b39853b5f
commit 58d6ecc490

View File

@ -48,38 +48,69 @@ class BaseFeed(Feed):
def item_categories(self, vlog): def item_categories(self, vlog):
return [vlog.package.category] return [vlog.package.category]
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]
class GlobalFeed(BaseFeed): class GlobalFeed(BaseFeed):
title = "euscan" title = "euscan"
link = "/" link = "/"
description = "Last euscan changes" description = "Last euscan changes"
def categories(self): def get_object(self, request):
return {"options": request.GET}
def categories(self, data):
categories = Package.objects.categories() categories = Package.objects.categories()
return [category['category'] for category in categories] return [category['category'] for category in categories]
def items(self): def _items(self, data):
return VersionLog.objects.order_by('-id')[:250] return VersionLog.objects.all(), 250
class PackageFeed(BaseFeed): class PackageFeed(BaseFeed):
feed_type = Atom1Feed feed_type = Atom1Feed
def get_object(self, request, category, package): def get_object(self, request, category, package):
return get_object_or_404(Package, category=category, name=package) return {
"obj": get_object_or_404(Package, category=category, name=package),
"options": request.GET,
}
def title(self, package): def title(self, data):
return "%s" % package return "%s" % data["obj"]
def link(self, package): def link(self, data):
return reverse('djeuscan.views.package', args=[package.category, return reverse('djeuscan.views.package', args=[data["obj"].category,
package.name]) data["obj"].name])
def description(self, package): def description(self, data):
return package.description return data["obj"].description
def items(self, package): def _items(self, data):
return VersionLog.objects.for_package(package, order=True)[:30] return VersionLog.objects.for_package(data["obj"]), 30
def item_description(self, vlog): def item_description(self, vlog):
return '' return ''
@ -89,39 +120,46 @@ class MaintainerFeed(BaseFeed):
feed_type = Atom1Feed feed_type = Atom1Feed
def get_object(self, request, maintainer_id): def get_object(self, request, maintainer_id):
return get_object_or_404(Maintainer, id=maintainer_id) return {
"obj": get_object_or_404(Maintainer, id=maintainer_id),
"options": request.GET,
}
def title(self, maintainer): def title(self, data):
return "%s" % maintainer return "%s" % data["obj"]
def description(self, maintainer): def description(self, data):
return "Last changes for %s" % maintainer return "Last changes for %s" % data["obj"]
def link(self, maintainer): def link(self, data):
return reverse('djeuscan.views.maintainer', return reverse('djeuscan.views.maintainer',
kwargs={'maintainer_id': maintainer.id}) kwargs={'maintainer_id': data["obj"].id})
def items(self, maintainer): def _items(self, data):
return VersionLog.objects.for_maintainer(maintainer, order=True)[:50] return VersionLog.objects.for_maintainer(data["obj"]), 50
class HerdFeed(BaseFeed): class HerdFeed(BaseFeed):
feed_type = Atom1Feed feed_type = Atom1Feed
def get_object(self, request, herd): def get_object(self, request, herd):
return get_object_or_404(Herd, herd=herd) return {
"obj": get_object_or_404(Herd, herd=herd),
"options": request.GET,
}
def title(self, herd): def title(self, data):
return "%s" % herd return "%s" % data["obj"]
def description(self, herd): def description(self, data):
return "Last changes for %s" % herd return "Last changes for %s" % data["obj"]
def link(self, herd): def link(self, data):
return reverse('djeuscan.views.herd', kwargs={'herd': herd.herd}) return reverse('djeuscan.views.herd',
kwargs={'herd': data["obj"].herd})
def items(self, herd): def _items(self, data):
return VersionLog.objects.for_herd(herd, order=True)[:100] return VersionLog.objects.for_herd(data["obj"]), 100
class CategoryFeed(BaseFeed): class CategoryFeed(BaseFeed):
@ -130,56 +168,46 @@ class CategoryFeed(BaseFeed):
def get_object(self, request, category): def get_object(self, request, category):
if not Package.objects.categories().count(): if not Package.objects.categories().count():
raise FeedDoesNotExist raise FeedDoesNotExist
return category return {
"obj": category,
"options": request.GET,
}
def title(self, category): def title(self, data):
return "%s" % category return "%s" % data["obj"]
def description(self, category): def description(self, data):
return "Last changes for %s" % category return "Last changes for %s" % data["obj"]
def link(self, category): def link(self, data):
return reverse('djeuscan.views.category', args=[category]) return reverse('djeuscan.views.category', args=[data["obj"]])
def items(self, category): def _items(self, data):
return VersionLog.objects.for_category(category, order=True)[:100] return VersionLog.objects.for_category(data["obj"]), 100
class UserFeed(BaseFeed): class UserFeed(BaseFeed):
link = "/" link = "/"
def description(self, data): def description(self, data):
return "%s - last euscan changes" return "%s - last euscan changes" % data["user"]
def title(self, data): def title(self, data):
return "%s - watched packages" % data[0] return "%s - watched packages" % data["user"]
def get_object(self, request): def get_object(self, request):
options = request.GET return {
return request.user, options "user": request.user,
"options": request.GET,
}
def items(self, data): def _items(self, data):
user, options = data user, options = data["user"], data["options"]
profile = get_profile(user) profile = get_profile(user)
packages = get_account_packages(user) packages = get_account_packages(user)
overlays = [o.name for o in profile.overlays.all()] overlays = [o.name for o in profile.overlays.all()]
ret = VersionLog.objects.filter( return VersionLog.objects.filter(
Q(package__in=packages) | Q(overlay__in=overlays) Q(package__in=packages) | Q(overlay__in=overlays)
) ), 100
# first of all consider options, then user preferences
if options:
upstream_info = "upstream_info" in options
portage_info = "portage_info" in options
else:
upstream_info = profile.upstream_info
portage_info = profile.portage_info
if not upstream_info:
ret = ret.exclude(overlay="")
if not portage_info:
ret = ret.exclude(~Q(overlay=""))
return ret.order_by("-datetime")[:100]