Commit a68b7b68 authored by Robert's avatar Robert

Limit feed size to 10 items

parent 82e3c3f7
import django
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from features.associations import models as associations
from features.groups import models as groups
from features.associations.models import Association
from features.groups.models import Group
class Index(django.contrib.syndication.views.Feed):
link = django.urls.reverse_lazy('index')
class IndexFeed(Feed):
link = reverse_lazy('index')
description_template = 'feeds/detail.html'
def items(self):
return associations.Association.objects.ordered_user_content(
django.contrib.auth.models.AnonymousUser())
return Association.objects.ordered_user_content(AnonymousUser())[:10]
def item_title(self, item):
return str(item)
......@@ -19,15 +22,15 @@ class Index(django.contrib.syndication.views.Feed):
return item.container.versions.first().time_created
def title(self):
return django.contrib.sites.models.Site.objects.get_current().name
return Site.objects.get_current().name
class Group(Index):
class GroupFeed(IndexFeed):
def get_object(self, request, group_pk):
return django.shortcuts.get_object_or_404(groups.Group, pk=group_pk)
return get_object_or_404(Group, pk=group_pk)
def items(self, obj):
return super().items().filter(group=obj)
return Association.objects.filter(group=obj).ordered_user_content(AnonymousUser())[:10]
def link(self, obj):
return obj.get_absolute_url()
......
......@@ -9,13 +9,13 @@ urlpatterns = [
name='index'),
url(
r'^stadt/feed/$',
feeds.Index(),
r'^stadt/feed.xml$',
feeds.IndexFeed(),
name='feed'),
url(
r'^stadt/groups/(?P<group_pk>[0-9]+)/feed/$',
feeds.Group(),
r'^stadt/groups/(?P<group_pk>[0-9]+)/feed.xml$',
feeds.GroupFeed(),
name='group-feed'),
url(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment