<NME> dashboard.py
<BEF> """Core dashboard views."""

import feedparser
import requests
from dateutil import parser
from requests.exceptions import RequestException

from django.contrib.auth import mixins as auth_mixins
from django.views import generic

from .. import signals

MODOBOA_WEBSITE_URL = "https://modoboa.org/"


class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
    """Dashboard view."""

    template_name = "core/dashboard.html"

    def dispatch(self, request, *args, **kwargs):
        """Check if user can access dashboard."""
        if not request.user.is_authenticated or not request.user.is_admin:
            return self.handle_no_permission()
        return super(DashboardView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        """Add context variables."""
        context = super(DashboardView, self).get_context_data(**kwargs)
        context.update({
            "selection": "dashboard", "widgets": {"left": [], "right": []}
        })
        # Fetch latest news
        if self.request.user.language == "fr":
            lang = "fr"
        else:
            lang = "en"
        context.update({"selection": "dashboard"})

        feed_url = "{}{}/weblog/feeds/".format(MODOBOA_WEBSITE_URL, lang)
        if self.request.user.role != "SuperAdmins":
            custom_feed_url = (
                self.request.localconfig.parameters.get_value("rss_feed_url"))
            if custom_feed_url:
                feed_url = custom_feed_url
        posts = feedparser.parse(feed_url)
        entries = []
        for entry in posts["entries"][:5]:
            entry["published"] = parser.parse(entry["published"])
            entries.append(entry)
        context["widgets"]["left"].append("core/_latest_news_widget.html")
        context.update({"news": entries})

            "hide_features_widget")
        if self.request.user.is_superuser or not hide_features_widget:
            url = "{}{}/api/projects/?featured=true".format(
            url = "{}{}/api/projects/?featured=true".format(
                MODOBOA_WEBSITE_URL, lang)
            features = []
            try:
                response = requests.get(url)
            except RequestException:
                pass
            else:
                if response.status_code == 200:
                    features = response.json()
            context["widgets"]["right"].append("core/_current_features.html")
            context.update({"features": features})

        result = signals.extra_admin_dashboard_widgets.send(
            sender=self.__class__, user=self.request.user)
        for _receiver, widgets in result:
            for widget in widgets:
                context["widgets"][widget["column"]].append(
                    widget["template"])
                # FIXME: can raise conflicts...
                context.update(widget["context"])

        return context

<MSG> Added setting to bypass dashboard RSS timeout

<DFF> @@ -8,6 +8,8 @@ from requests.exceptions import RequestException
 from django.contrib.auth import mixins as auth_mixins
 from django.views import generic
 
+from django.conf import settings
+
 from .. import signals
 
 MODOBOA_WEBSITE_URL = "https://modoboa.org/"
@@ -43,11 +45,13 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
                 self.request.localconfig.parameters.get_value("rss_feed_url"))
             if custom_feed_url:
                 feed_url = custom_feed_url
-        posts = feedparser.parse(feed_url)
+        if not settings.DISABLE_RSS:
+            posts = feedparser.parse(feed_url)
         entries = []
-        for entry in posts["entries"][:5]:
-            entry["published"] = parser.parse(entry["published"])
-            entries.append(entry)
+        if not settings.DISABLE_RSS:
+            for entry in posts["entries"][:5]:
+                entry["published"] = parser.parse(entry["published"])
+                entries.append(entry)
         context["widgets"]["left"].append("core/_latest_news_widget.html")
         context.update({"news": entries})
 
@@ -57,13 +61,14 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
             url = "{}{}/api/projects/?featured=true".format(
                 MODOBOA_WEBSITE_URL, lang)
             features = []
-            try:
-                response = requests.get(url)
-            except RequestException:
-                pass
-            else:
-                if response.status_code == 200:
-                    features = response.json()
+            if not settings.DISABLE_RSS:
+                try:
+                    response = requests.get(url)
+                except RequestException:
+                    pass
+                else:
+                    if response.status_code == 200:
+                        features = response.json()
             context["widgets"]["right"].append("core/_current_features.html")
             context.update({"features": features})
 

Added setting to bypass dashboard RSS timeout