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}'
|
||||
|
||||
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
|
||||
|
@ -1,4 +1,5 @@
|
||||
<div class="list-group list-group-flush">
|
||||
{% if not feed.bozo %}
|
||||
<div class="list-group list-group-flush">
|
||||
{% for entry in feed.entries %}
|
||||
<div class="list-group-item px-1">
|
||||
<h6><a href="{{ entry.link }}">{{ entry.title }}</a></h6>
|
||||
@ -9,5 +10,13 @@
|
||||
{% empty %}
|
||||
<div class="list-group-item text-muted">No content found</div>
|
||||
{% 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