mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #12062: Avoid caching invalid RSS feed content
This commit is contained in:
@ -193,14 +193,16 @@ class RSSFeedWidget(DashboardWidget):
|
|||||||
return f'dashboard_rss_{url_checksum}'
|
return f'dashboard_rss_{url_checksum}'
|
||||||
|
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
# Fetch RSS content from cache
|
# Fetch RSS content from cache if available
|
||||||
if feed_content := cache.get(self.cache_key):
|
if feed_content := cache.get(self.cache_key):
|
||||||
feed = feedparser.FeedParserDict(feed_content)
|
feed = feedparser.FeedParserDict(feed_content)
|
||||||
else:
|
else:
|
||||||
feed = feedparser.parse(self.config['feed_url'])
|
feed = feedparser.parse(self.config['feed_url'])
|
||||||
|
if not feed.bozo:
|
||||||
# Cap number of entries
|
# Cap number of entries
|
||||||
max_entries = self.config.get('max_entries')
|
max_entries = self.config.get('max_entries')
|
||||||
feed['entries'] = feed['entries'][:max_entries]
|
feed['entries'] = feed['entries'][:max_entries]
|
||||||
|
# Cache the feed content
|
||||||
cache.set(self.cache_key, dict(feed), self.config.get('cache_timeout'))
|
cache.set(self.cache_key, dict(feed), self.config.get('cache_timeout'))
|
||||||
|
|
||||||
return feed
|
return feed
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{% if not feed.bozo %}
|
||||||
<div class="list-group list-group-flush">
|
<div class="list-group list-group-flush">
|
||||||
{% for entry in feed.entries %}
|
{% for entry in feed.entries %}
|
||||||
<div class="list-group-item px-1">
|
<div class="list-group-item px-1">
|
||||||
@ -10,4 +11,12 @@
|
|||||||
<div class="list-group-item text-muted">No content found</div>
|
<div class="list-group-item text-muted">No content found</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{# There was an error retrieving/parsing the feed #}
|
||||||
|
<span class="text-danger">
|
||||||
|
<i class="mdi mdi-alert"></i> There was a problem fetching the RSS feed:
|
||||||
|
</span>
|
||||||
|
<pre class="m-2">
|
||||||
|
Response status: {{ feed.status }}
|
||||||
|
Error: {{ feed.bozo_exception|escape }}</pre>
|
||||||
|
{% endif %}
|
||||||
|
Reference in New Issue
Block a user