diff --git a/euscanwww/djeuscan/feeds.py b/euscanwww/djeuscan/feeds.py index e8045b1..684f191 100644 --- a/euscanwww/djeuscan/feeds.py +++ b/euscanwww/djeuscan/feeds.py @@ -4,6 +4,7 @@ from django.utils.feedgenerator import Atom1Feed from django.core.urlresolvers import reverse from djeuscan.models import Package, Herd, Maintainer, VersionLog +from djeuscan.helpers import get_profile, get_account_packages class BaseFeed(Feed): @@ -141,3 +142,25 @@ class CategoryFeed(BaseFeed): def items(self, category): 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): + packages = get_account_packages(user) + overlays = [o.name for o in get_profile(user).overlays.all()] + + ret = VersionLog.objects.filter(package__in=packages).filter( + overlay__in=overlays).order_by("-datetime")[:100] + + return ret diff --git a/euscanwww/djeuscan/helpers.py b/euscanwww/djeuscan/helpers.py index c05daaf..f6361b6 100644 --- a/euscanwww/djeuscan/helpers.py +++ b/euscanwww/djeuscan/helpers.py @@ -3,6 +3,7 @@ djeuscan.helpers """ from distutils.version import StrictVersion, LooseVersion +from django.db.models import Q def xint(i): @@ -106,3 +107,19 @@ def get_account_maintainers(user): ids = [obj.pk for obj in get_profile(user).maintainers.all()] return Package.objects.maintainers(ids=ids) + +def get_account_packages(user): + """ + Returns all watched packages + """ + from djeuscan.models import Package + + profile = get_profile(user) + q_categories = Q(category__in=[ + category.name for category in profile.categories.all()]) + q_herds = Q(herds__in=profile.herds.all()) + q_maintainers = Q(maintainers__in=profile.maintainers.all()) + packages = list(profile.packages.all()) + list(Package.objects.filter( + q_categories | q_herds | q_maintainers)) + + return packages diff --git a/euscanwww/djeuscan/templates/euscan/accounts/index.html b/euscanwww/djeuscan/templates/euscan/accounts/index.html index 7db53f3..7796f3e 100644 --- a/euscanwww/djeuscan/templates/euscan/accounts/index.html +++ b/euscanwww/djeuscan/templates/euscan/accounts/index.html @@ -6,6 +6,15 @@ {{ block.super }} - Welcome {{ user }} {% endblock %} +{% block menu_feed %} +{{ block.super }} +