general: add option to limit the number of displayed feed entries (#10389)
This commit is contained in:
parent
8480bae3b5
commit
22ca41af96
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('data', '0015_feedcell_title'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='feedcell',
|
||||
name='limit',
|
||||
field=models.PositiveSmallIntegerField(null=True, verbose_name='Maximum number of entries', blank=True),
|
||||
),
|
||||
]
|
|
@ -549,6 +549,8 @@ class LinkCell(CellBase):
|
|||
class FeedCell(CellBase):
|
||||
title = models.CharField(_('Title'), max_length=150, blank=True)
|
||||
url = models.URLField(_('URL'), blank=True)
|
||||
limit = models.PositiveSmallIntegerField(_('Maximum number of entries'),
|
||||
null=True, blank=True)
|
||||
|
||||
template_name = 'combo/feed-cell.html'
|
||||
|
||||
|
@ -569,6 +571,8 @@ class FeedCell(CellBase):
|
|||
cache.set(cache_key, feed_content, 600)
|
||||
if feed_content:
|
||||
context['feed'] = feedparser.parse(feed_content)
|
||||
if self.limit:
|
||||
context['feed']['entries'] = context['feed']['entries'][:self.limit]
|
||||
if not self.title:
|
||||
try:
|
||||
self.title = context['feed']['feed'].title
|
||||
|
|
Loading…
Reference in New Issue