Projet

Général

Profil

« Précédent | Suivant » 

Révision 5c367ca4

Ajouté par Serghei Mihai il y a environ 7 ans

limit items in rss feed (#14798)

Voir les différences:

corbo/settings.py
119 119
RSS_DESCRIPTION = ''
120 120
RSS_LINK = ''
121 121
RSS_LINK_TEMPLATE = '/#announce{0}'
122
RSS_ITEMS_LIMIT = 15
122 123

  
123 124
# Authentication settings
124 125
try:
corbo/views.py
202 202
        self.__dict__.update(kwargs)
203 203

  
204 204
    def items(self):
205
        limit = settings.RSS_ITEMS_LIMIT
205 206
        return models.Announce.objects.filter(publication_time__lte=timezone.now()).exclude(
206
            expiration_time__lt=timezone.now()).order_by('-publication_time')
207
            expiration_time__lt=timezone.now()).order_by('-publication_time')[:limit]
207 208

  
208 209
    def item_title(self, item):
209 210
        return item.title
tests/test_announces.py
6 6
from django.core.files.storage import DefaultStorage
7 7
from django.utils import timezone
8 8
from django.core.urlresolvers import reverse
9
from django.conf import settings
9 10

  
10 11
from corbo.models import Category, Announce
11 12

  
......
85 86
    a.save()
86 87
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
87 88
    assert len(feed_content['entries']) == 0
89

  
90
def test_rss_feed_items(app):
91
    c = Category.objects.create(name='Test announces')
92
    for i in xrange(10):
93
        a = Announce.objects.create(category=c, title='Test %s' % i,
94
                                    publication_time=timezone.now(),
95
                                    text='text of announce %s' % i)
96
    feed_content = feedparser.parse(app.get(reverse('atom')).text)
97
    assert len(feed_content['entries']) <= settings.RSS_ITEMS_LIMIT
98
    for i in xrange(i, 10):
99
        a = Announce.objects.create(category=c, title='Test %s' % i,
100
                                    publication_time=timezone.now(),
101
                                    text='text of announce %s' % i)
102
    assert len(feed_content['entries']) <= settings.RSS_ITEMS_LIMIT

Formats disponibles : Unified diff