euscanwww: Adding basic custom user feed

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-08-08 13:30:56 +02:00
parent 2b75908205
commit edb8d88fb6
4 changed files with 52 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from django.utils.feedgenerator import Atom1Feed
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from djeuscan.models import Package, Herd, Maintainer, VersionLog from djeuscan.models import Package, Herd, Maintainer, VersionLog
from djeuscan.helpers import get_profile, get_account_packages
class BaseFeed(Feed): class BaseFeed(Feed):
@ -141,3 +142,25 @@ class CategoryFeed(BaseFeed):
def items(self, category): def items(self, category):
return VersionLog.objects.for_category(category, order=True)[:100] 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

View File

@ -3,6 +3,7 @@ djeuscan.helpers
""" """
from distutils.version import StrictVersion, LooseVersion from distutils.version import StrictVersion, LooseVersion
from django.db.models import Q
def xint(i): def xint(i):
@ -106,3 +107,19 @@ def get_account_maintainers(user):
ids = [obj.pk for obj in get_profile(user).maintainers.all()] ids = [obj.pk for obj in get_profile(user).maintainers.all()]
return Package.objects.maintainers(ids=ids) 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

View File

@ -6,6 +6,15 @@
{{ block.super }} - Welcome {{ user }} {{ block.super }} - Welcome {{ user }}
{% endblock %} {% endblock %}
{% block menu_feed %}
{{ block.super }}
<li>
<img src="{{ STATIC_URL }}/img/feed.png" alt="feed" />
<a title="{{ user }} Feed" href="{% url "user_feed" %}">
{{ user }}'s Feed
</a>
</li>
{% endblock %}
{% block content %} {% block content %}
<h2> <h2>

View File

@ -7,7 +7,7 @@ from djcelery.views import apply as apply_task
from djeuscan.views import registered_tasks from djeuscan.views import registered_tasks
from djeuscan.feeds import PackageFeed, CategoryFeed, HerdFeed, \ from djeuscan.feeds import PackageFeed, CategoryFeed, HerdFeed, \
MaintainerFeed, GlobalFeed MaintainerFeed, GlobalFeed, UserFeed
admin_required = user_passes_test(lambda u: u.is_superuser) 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'^packages/$', 'accounts_packages', name="accounts_packages"),
url(r'^overlays/$', 'accounts_overlays', name="accounts_overlays"), url(r'^overlays/$', 'accounts_overlays', name="accounts_overlays"),
url(r'^feed/$', UserFeed(), name='user_feed'),
url(r'^logout/$', logout, {'next_page': '/'}), url(r'^logout/$', logout, {'next_page': '/'}),
url(r'^password/change/done/$', url(r'^password/change/done/$',