1
0
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:
jeremystretch
2023-03-27 09:29:51 -04:00
parent 37aa07eea1
commit 669cfe8952
2 changed files with 28 additions and 17 deletions

View File

@ -193,14 +193,16 @@ class RSSFeedWidget(DashboardWidget):
return f'dashboard_rss_{url_checksum}'
def get_feed(self):
# Fetch RSS content from cache
# Fetch RSS content from cache if available
if feed_content := cache.get(self.cache_key):
feed = feedparser.FeedParserDict(feed_content)
else:
feed = feedparser.parse(self.config['feed_url'])
if not feed.bozo:
# Cap number of entries
max_entries = self.config.get('max_entries')
feed['entries'] = feed['entries'][:max_entries]
# Cache the feed content
cache.set(self.cache_key, dict(feed), self.config.get('cache_timeout'))
return feed

View File

@ -1,3 +1,4 @@
{% if not feed.bozo %}
<div class="list-group list-group-flush">
{% for entry in feed.entries %}
<div class="list-group-item px-1">
@ -10,4 +11,12 @@
<div class="list-group-item text-muted">No content found</div>
{% endfor %}
</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 %}