Add config option on RSSFeedWidget to specify requires_internet and to display a more appropriate error if ISOLATED_DEPLOYMENT is set

This commit is contained in:
Brian Tiemann 2024-12-10 13:29:29 -05:00
parent 01d9f101dd
commit 43bfee94f0
3 changed files with 14 additions and 0 deletions

View File

@ -79,6 +79,7 @@ DEFAULT_DASHBOARD = [
'feed_url': 'http://netbox.dev/rss/', 'feed_url': 'http://netbox.dev/rss/',
'max_entries': 10, 'max_entries': 10,
'cache_timeout': 14400, 'cache_timeout': 14400,
'requires_internet': True,
} }
}, },
{ {

View File

@ -275,6 +275,7 @@ class RSSFeedWidget(DashboardWidget):
default_config = { default_config = {
'max_entries': 10, 'max_entries': 10,
'cache_timeout': 3600, # seconds 'cache_timeout': 3600, # seconds
'requires_internet': True,
} }
description = _('Embed an RSS feed from an external website.') description = _('Embed an RSS feed from an external website.')
template_name = 'extras/dashboard/widgets/rssfeed.html' template_name = 'extras/dashboard/widgets/rssfeed.html'
@ -285,6 +286,9 @@ class RSSFeedWidget(DashboardWidget):
feed_url = forms.URLField( feed_url = forms.URLField(
label=_('Feed URL') label=_('Feed URL')
) )
requires_internet = forms.BooleanField(
label=_('Requires external connection')
)
max_entries = forms.IntegerField( max_entries = forms.IntegerField(
min_value=1, min_value=1,
max_value=1000, max_value=1000,
@ -309,6 +313,11 @@ class RSSFeedWidget(DashboardWidget):
return f'dashboard_rss_{url_checksum}' return f'dashboard_rss_{url_checksum}'
def get_feed(self): def get_feed(self):
if self.config['requires_internet'] and settings.ISOLATED_DEPLOYMENT:
return {
'isolated_deployment': True,
}
# Fetch RSS content from cache if available # Fetch RSS content from cache if available
if feed_content := cache.get(self.cache_key): if feed_content := cache.get(self.cache_key):
return { return {

View File

@ -12,6 +12,10 @@
<div class="list-group-item text-muted">{% trans "No content found" %}</div> <div class="list-group-item text-muted">{% trans "No content found" %}</div>
{% endfor %} {% endfor %}
</div> </div>
{% elif isolated_deployment %}
<span class="text-danger">
<i class="mdi mdi-alert"></i> {% trans "This RSS feed requires an external connection. Check the ISOLATED_DEPLOYMENT setting." %}
</span>
{% else %} {% else %}
{# There was an error retrieving/parsing the feed #} {# There was an error retrieving/parsing the feed #}
<span class="text-danger"> <span class="text-danger">