From edb8d88fb6694f03c837e2e703eca7184cd7a1fa Mon Sep 17 00:00:00 2001 From: volpino Date: Wed, 8 Aug 2012 13:30:56 +0200 Subject: [PATCH] euscanwww: Adding basic custom user feed Signed-off-by: volpino --- euscanwww/djeuscan/feeds.py | 23 +++++++++++++++++++ euscanwww/djeuscan/helpers.py | 17 ++++++++++++++ .../templates/euscan/accounts/index.html | 9 ++++++++ euscanwww/djeuscan/urls.py | 4 +++- 4 files changed, 52 insertions(+), 1 deletion(-) 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 }} +
  • + feed + + {{ user }}'s Feed + +
  • +{% endblock %} {% block content %}

    diff --git a/euscanwww/djeuscan/urls.py b/euscanwww/djeuscan/urls.py index c53b298..87de27b 100644 --- a/euscanwww/djeuscan/urls.py +++ b/euscanwww/djeuscan/urls.py @@ -7,7 +7,7 @@ from djcelery.views import apply as apply_task from djeuscan.views import registered_tasks from djeuscan.feeds import PackageFeed, CategoryFeed, HerdFeed, \ - MaintainerFeed, GlobalFeed + MaintainerFeed, GlobalFeed, UserFeed admin_required = user_passes_test(lambda u: u.is_superuser) @@ -94,6 +94,8 @@ accounts_patterns = patterns('djeuscan.views', url(r'^packages/$', 'accounts_packages', name="accounts_packages"), url(r'^overlays/$', 'accounts_overlays', name="accounts_overlays"), + url(r'^feed/$', UserFeed(), name='user_feed'), + url(r'^logout/$', logout, {'next_page': '/'}), url(r'^password/change/done/$',