prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Dashboard - server behind proxy
  # Impacted versions
  
  * Modoboa: 1.14.0
  * Webserver: Nginx
  
  # Steps to reproduce
  Modoboa server is behind proxy, so no internet direct access
  Acces dashboard via admin account
  
  # Current behavior
  504 Gateway Time-out
  
  # Expected behavior
  no error
  
  
  </issue>
  <code>
  [start of modoboa/core/views/dashboard.py]
  1 """Core dashboard views."""
  2 
  3 import feedparser
  4 import requests
  5 from dateutil import parser
  6 from requests.exceptions import RequestException
  7 
  8 from django.contrib.auth import mixins as auth_mixins
  9 from django.views import generic
  10 
  11 from .. import signals
  12 
  13 MODOBOA_WEBSITE_URL = "https://modoboa.org/"
  14 
  15 
  16 class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
  17     """Dashboard view."""
  18 
  19     template_name = "core/dashboard.html"
  20 
  21     def dispatch(self, request, *args, **kwargs):
  22         """Check if user can access dashboard."""
  23         if not request.user.is_authenticated or not request.user.is_admin:
  24             return self.handle_no_permission()
  25         return super(DashboardView, self).dispatch(request, *args, **kwargs)
  26 
  27     def get_context_data(self, **kwargs):
  28         """Add context variables."""
  29         context = super(DashboardView, self).get_context_data(**kwargs)
  30         context.update({
  31             "selection": "dashboard", "widgets": {"left": [], "right": []}
  32         })
  33         # Fetch latest news
  34         if self.request.user.language == "fr":
  35             lang = "fr"
  36         else:
  37             lang = "en"
  38         context.update({"selection": "dashboard"})
  39 
  40         feed_url = "{}{}/weblog/feeds/".format(MODOBOA_WEBSITE_URL, lang)
  41         if self.request.user.role != "SuperAdmins":
  42             custom_feed_url = (
  43                 self.request.localconfig.parameters.get_value("rss_feed_url"))
  44             if custom_feed_url:
  45                 feed_url = custom_feed_url
  46         posts = feedparser.parse(feed_url)
  47         entries = []
  48         for entry in posts["entries"][:5]:
  49             entry["published"] = parser.parse(entry["published"])
  50             entries.append(entry)
  51         context["widgets"]["left"].append("core/_latest_news_widget.html")
  52         context.update({"news": entries})
  53 
  54         hide_features_widget = self.request.localconfig.parameters.get_value(
  55             "hide_features_widget")
  56         if self.request.user.is_superuser or not hide_features_widget:
  57             url = "{}{}/api/projects/?featured=true".format(
  58                 MODOBOA_WEBSITE_URL, lang)
  59             features = []
  60             try:
  61                 response = requests.get(url)
  62             except RequestException:
  63                 pass
  64             else:
  65                 if response.status_code == 200:
  66                     features = response.json()
  67             context["widgets"]["right"].append("core/_current_features.html")
  68             context.update({"features": features})
  69 
  70         # Extra widgets
  71         result = signals.extra_admin_dashboard_widgets.send(
  72             sender=self.__class__, user=self.request.user)
  73         for _receiver, widgets in result:
  74             for widget in widgets:
  75                 context["widgets"][widget["column"]].append(
  76                     widget["template"])
  77                 # FIXME: can raise conflicts...
  78                 context.update(widget["context"])
  79 
  80         return context
  81
  [end of modoboa/core/views/dashboard.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/modoboa/core/views/dashboard.py b/modoboa/core/views/dashboard.py
  --- a/modoboa/core/views/dashboard.py
  +++ b/modoboa/core/views/dashboard.py
  @@ -8,6 +8,8 @@
   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,12 @@
                   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)
  +        if not settings.DISABLE_DASHBOARD_EXTERNAL_QUERIES:
  +            posts = feedparser.parse(feed_url)
  +            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 +60,14 @@
               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_DASHBOARD_EXTERNAL_QUERIES:
  +                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})
  
verification_info: {"golden_diff": "diff --git a/modoboa/core/views/dashboard.py b/modoboa/core/views/dashboard.py\n--- a/modoboa/core/views/dashboard.py\n+++ b/modoboa/core/views/dashboard.py\n@@ -8,6 +8,8 @@\n from django.contrib.auth import mixins as auth_mixins\n from django.views import generic\n \n+from django.conf import settings\n+\n from .. import signals\n \n MODOBOA_WEBSITE_URL = \"https://modoboa.org/\"\n@@ -43,11 +45,12 @@\n                 self.request.localconfig.parameters.get_value(\"rss_feed_url\"))\n             if custom_feed_url:\n                 feed_url = custom_feed_url\n-        posts = feedparser.parse(feed_url)\n         entries = []\n-        for entry in posts[\"entries\"][:5]:\n-            entry[\"published\"] = parser.parse(entry[\"published\"])\n-            entries.append(entry)\n+        if not settings.DISABLE_DASHBOARD_EXTERNAL_QUERIES:\n+            posts = feedparser.parse(feed_url)\n+            for entry in posts[\"entries\"][:5]:\n+                entry[\"published\"] = parser.parse(entry[\"published\"])\n+                entries.append(entry)\n         context[\"widgets\"][\"left\"].append(\"core/_latest_news_widget.html\")\n         context.update({\"news\": entries})\n \n@@ -57,13 +60,14 @@\n             url = \"{}{}/api/projects/?featured=true\".format(\n                 MODOBOA_WEBSITE_URL, lang)\n             features = []\n-            try:\n-                response = requests.get(url)\n-            except RequestException:\n-                pass\n-            else:\n-                if response.status_code == 200:\n-                    features = response.json()\n+            if not settings.DISABLE_DASHBOARD_EXTERNAL_QUERIES:\n+                try:\n+                    response = requests.get(url)\n+                except RequestException:\n+                    pass\n+                else:\n+                    if response.status_code == 200:\n+                        features = response.json()\n             context[\"widgets\"][\"right\"].append(\"core/_current_features.html\")\n             context.update({\"features\": features})\n", "issue": "Dashboard - server behind proxy\n# Impacted versions\r\n\r\n* Modoboa: 1.14.0\r\n* Webserver: Nginx\r\n\r\n# Steps to reproduce\r\nModoboa server is behind proxy, so no internet direct access\r\nAcces dashboard via admin account\r\n\r\n# Current behavior\r\n504 Gateway Time-out\r\n\r\n# Expected behavior\r\nno error\r\n\n", "before_files": [{"content": "\"\"\"Core dashboard views.\"\"\"\n\nimport feedparser\nimport requests\nfrom dateutil import parser\nfrom requests.exceptions import RequestException\n\nfrom django.contrib.auth import mixins as auth_mixins\nfrom django.views import generic\n\nfrom .. import signals\n\nMODOBOA_WEBSITE_URL = \"https://modoboa.org/\"\n\n\nclass DashboardView(auth_mixins.AccessMixin, generic.TemplateView):\n    \"\"\"Dashboard view.\"\"\"\n\n    template_name = \"core/dashboard.html\"\n\n    def dispatch(self, request, *args, **kwargs):\n        \"\"\"Check if user can access dashboard.\"\"\"\n        if not request.user.is_authenticated or not request.user.is_admin:\n            return self.handle_no_permission()\n        return super(DashboardView, self).dispatch(request, *args, **kwargs)\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Add context variables.\"\"\"\n        context = super(DashboardView, self).get_context_data(**kwargs)\n        context.update({\n            \"selection\": \"dashboard\", \"widgets\": {\"left\": [], \"right\": []}\n        })\n        # Fetch latest news\n        if self.request.user.language == \"fr\":\n            lang = \"fr\"\n        else:\n            lang = \"en\"\n        context.update({\"selection\": \"dashboard\"})\n\n        feed_url = \"{}{}/weblog/feeds/\".format(MODOBOA_WEBSITE_URL, lang)\n        if self.request.user.role != \"SuperAdmins\":\n            custom_feed_url = (\n                self.request.localconfig.parameters.get_value(\"rss_feed_url\"))\n            if custom_feed_url:\n                feed_url = custom_feed_url\n        posts = feedparser.parse(feed_url)\n        entries = []\n        for entry in posts[\"entries\"][:5]:\n            entry[\"published\"] = parser.parse(entry[\"published\"])\n            entries.append(entry)\n        context[\"widgets\"][\"left\"].append(\"core/_latest_news_widget.html\")\n        context.update({\"news\": entries})\n\n        hide_features_widget = self.request.localconfig.parameters.get_value(\n            \"hide_features_widget\")\n        if self.request.user.is_superuser or not hide_features_widget:\n            url = \"{}{}/api/projects/?featured=true\".format(\n                MODOBOA_WEBSITE_URL, lang)\n            features = []\n            try:\n                response = requests.get(url)\n            except RequestException:\n                pass\n            else:\n                if response.status_code == 200:\n                    features = response.json()\n            context[\"widgets\"][\"right\"].append(\"core/_current_features.html\")\n            context.update({\"features\": features})\n\n        # Extra widgets\n        result = signals.extra_admin_dashboard_widgets.send(\n            sender=self.__class__, user=self.request.user)\n        for _receiver, widgets in result:\n            for widget in widgets:\n                context[\"widgets\"][widget[\"column\"]].append(\n                    widget[\"template\"])\n                # FIXME: can raise conflicts...\n                context.update(widget[\"context\"])\n\n        return context\n", "path": "modoboa/core/views/dashboard.py"}]}