prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  T - Fix post-sign-ins redirect so that user lands on correct page
  **Summary**
  You're not taken back to where you were when you sign in. At least via the modal and GitHub.
  
  ![Screen-Recording-2020-04-03-at-2 31 33-PM](https://user-images.githubusercontent.com/26739/78393569-167dd900-75b8-11ea-9d78-3bf0ca358bb2.gif)
  
  
  **Steps To Reproduce (STR)**
  
  
  1. Go to some page other than the home page. Be not-signed in.
  2. Click sign in. 
  3. Click GitHub and complete your GitHub auth stuff
  
  
  **Actual behavior**
  I ended up back on the home page `/en-US/`. :(
  
  
  **Expected behavior**
  To be taken to the page I was originally on. 
  
  
  **Additional context**
  Pretty sure this is regression but don't know if it started when we switched to a modal. 
  
  
  </issue>
  <code>
  [start of kuma/core/context_processors.py]
  1 from urllib.parse import urlparse
  2 
  3 from constance import config
  4 from django.conf import settings
  5 from django.utils import translation
  6 
  7 from .i18n import get_language_mapping
  8 
  9 
  10 def global_settings(request):
  11     """Adds settings to the context."""
  12 
  13     def clean_safe_url(url):
  14         if "://" not in url:
  15             # E.g. 'elasticsearch:9200'
  16             url = "http://" + url
  17         parsed = urlparse(url)
  18         if "@" in parsed.netloc:
  19             parsed = parsed._replace(
  20                 netloc="username:secret@" + parsed.netloc.split("@")[-1]
  21             )
  22         return parsed.geturl()
  23 
  24     # TODO: Ideally, GOOGLE_ANALYTICS_ACCOUNT is only set in settings (from
  25     # an environment variable) but for safe transition, we rely on
  26     # constance if it hasn't been put into settings yet.
  27     # Once we know with confidence, that GOOGLE_ANALYTICS_ACCOUNT is set
  28     # and a valid value in the environment (for production!) then we
  29     # can delete these lines of code.
  30     # See https://bugzilla.mozilla.org/show_bug.cgi?id=1570076
  31     google_analytics_account = getattr(settings, "GOOGLE_ANALYTICS_ACCOUNT", None)
  32     if google_analytics_account is None:
  33         if config.GOOGLE_ANALYTICS_ACCOUNT != "0":
  34             settings.GOOGLE_ANALYTICS_ACCOUNT = config.GOOGLE_ANALYTICS_ACCOUNT
  35 
  36     return {
  37         "settings": settings,
  38         # Because the 'settings.ES_URLS' might contain the username:password
  39         # it's never appropriate to display in templates. So clean them up.
  40         # But return it as a lambda so it only executes if really needed.
  41         "safe_es_urls": lambda: [clean_safe_url(x) for x in settings.ES_URLS],
  42     }
  43 
  44 
  45 def i18n(request):
  46     return {
  47         "LANGUAGES": get_language_mapping(),
  48         "LANG": (
  49             settings.LANGUAGE_URL_MAP.get(translation.get_language())
  50             or translation.get_language()
  51         ),
  52         "DIR": "rtl" if translation.get_language_bidi() else "ltr",
  53     }
  54 
  55 
  56 def next_url(request):
  57     if (
  58         hasattr(request, "path")
  59         and "login" not in request.path
  60         and "register" not in request.path
  61     ):
  62         return {"next_url": request.get_full_path()}
  63     return {}
  64
  [end of kuma/core/context_processors.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/kuma/core/context_processors.py b/kuma/core/context_processors.py
  --- a/kuma/core/context_processors.py
  +++ b/kuma/core/context_processors.py
  @@ -4,6 +4,8 @@
   from django.conf import settings
   from django.utils import translation
   
  +from kuma.core.urlresolvers import reverse
  +
   from .i18n import get_language_mapping
   
   
  @@ -54,10 +56,30 @@
   
   
   def next_url(request):
  -    if (
  -        hasattr(request, "path")
  -        and "login" not in request.path
  -        and "register" not in request.path
  -    ):
  -        return {"next_url": request.get_full_path()}
  -    return {}
  +    """Return a function by the same name as the context processor.
  +    That means, in the jinja templates, instead of doing
  +
  +        {% set url = next_url %}
  +
  +    you just have to do:
  +
  +        {% set url = next_url() %}
  +
  +    which means that the actual context processor function isn't executed
  +    every single time any jinja template is rendered. Now, only if the
  +    context processor is actually needed, it gets executed.
  +
  +    See https://www.peterbe.com/plog/closure-django-context-processors
  +    """
  +
  +    def inner():
  +        if hasattr(request, "path"):
  +            if request.GET.get("next"):
  +                if "://" not in request.GET["next"]:
  +                    return request.GET["next"]
  +            elif reverse(settings.LOGIN_URL) != request.get_full_path():
  +                # The only exception is the sign-in landing page which you get to
  +                # if you can't use the auth modal.
  +                return request.get_full_path()
  +
  +    return {"next_url": inner}
  
verification_info: {"golden_diff": "diff --git a/kuma/core/context_processors.py b/kuma/core/context_processors.py\n--- a/kuma/core/context_processors.py\n+++ b/kuma/core/context_processors.py\n@@ -4,6 +4,8 @@\n from django.conf import settings\n from django.utils import translation\n \n+from kuma.core.urlresolvers import reverse\n+\n from .i18n import get_language_mapping\n \n \n@@ -54,10 +56,30 @@\n \n \n def next_url(request):\n-    if (\n-        hasattr(request, \"path\")\n-        and \"login\" not in request.path\n-        and \"register\" not in request.path\n-    ):\n-        return {\"next_url\": request.get_full_path()}\n-    return {}\n+    \"\"\"Return a function by the same name as the context processor.\n+    That means, in the jinja templates, instead of doing\n+\n+        {% set url = next_url %}\n+\n+    you just have to do:\n+\n+        {% set url = next_url() %}\n+\n+    which means that the actual context processor function isn't executed\n+    every single time any jinja template is rendered. Now, only if the\n+    context processor is actually needed, it gets executed.\n+\n+    See https://www.peterbe.com/plog/closure-django-context-processors\n+    \"\"\"\n+\n+    def inner():\n+        if hasattr(request, \"path\"):\n+            if request.GET.get(\"next\"):\n+                if \"://\" not in request.GET[\"next\"]:\n+                    return request.GET[\"next\"]\n+            elif reverse(settings.LOGIN_URL) != request.get_full_path():\n+                # The only exception is the sign-in landing page which you get to\n+                # if you can't use the auth modal.\n+                return request.get_full_path()\n+\n+    return {\"next_url\": inner}\n", "issue": "T - Fix post-sign-ins redirect so that user lands on correct page\n**Summary**\r\nYou're not taken back to where you were when you sign in. At least via the modal and GitHub.\r\n\r\n![Screen-Recording-2020-04-03-at-2 31 33-PM](https://user-images.githubusercontent.com/26739/78393569-167dd900-75b8-11ea-9d78-3bf0ca358bb2.gif)\r\n\r\n\r\n**Steps To Reproduce (STR)**\r\n\r\n\r\n1. Go to some page other than the home page. Be not-signed in.\r\n2. Click sign in. \r\n3. Click GitHub and complete your GitHub auth stuff\r\n\r\n\r\n**Actual behavior**\r\nI ended up back on the home page `/en-US/`. :(\r\n\r\n\r\n**Expected behavior**\r\nTo be taken to the page I was originally on. \r\n\r\n\r\n**Additional context**\r\nPretty sure this is regression but don't know if it started when we switched to a modal. \r\n\n", "before_files": [{"content": "from urllib.parse import urlparse\n\nfrom constance import config\nfrom django.conf import settings\nfrom django.utils import translation\n\nfrom .i18n import get_language_mapping\n\n\ndef global_settings(request):\n    \"\"\"Adds settings to the context.\"\"\"\n\n    def clean_safe_url(url):\n        if \"://\" not in url:\n            # E.g. 'elasticsearch:9200'\n            url = \"http://\" + url\n        parsed = urlparse(url)\n        if \"@\" in parsed.netloc:\n            parsed = parsed._replace(\n                netloc=\"username:secret@\" + parsed.netloc.split(\"@\")[-1]\n            )\n        return parsed.geturl()\n\n    # TODO: Ideally, GOOGLE_ANALYTICS_ACCOUNT is only set in settings (from\n    # an environment variable) but for safe transition, we rely on\n    # constance if it hasn't been put into settings yet.\n    # Once we know with confidence, that GOOGLE_ANALYTICS_ACCOUNT is set\n    # and a valid value in the environment (for production!) then we\n    # can delete these lines of code.\n    # See https://bugzilla.mozilla.org/show_bug.cgi?id=1570076\n    google_analytics_account = getattr(settings, \"GOOGLE_ANALYTICS_ACCOUNT\", None)\n    if google_analytics_account is None:\n        if config.GOOGLE_ANALYTICS_ACCOUNT != \"0\":\n            settings.GOOGLE_ANALYTICS_ACCOUNT = config.GOOGLE_ANALYTICS_ACCOUNT\n\n    return {\n        \"settings\": settings,\n        # Because the 'settings.ES_URLS' might contain the username:password\n        # it's never appropriate to display in templates. So clean them up.\n        # But return it as a lambda so it only executes if really needed.\n        \"safe_es_urls\": lambda: [clean_safe_url(x) for x in settings.ES_URLS],\n    }\n\n\ndef i18n(request):\n    return {\n        \"LANGUAGES\": get_language_mapping(),\n        \"LANG\": (\n            settings.LANGUAGE_URL_MAP.get(translation.get_language())\n            or translation.get_language()\n        ),\n        \"DIR\": \"rtl\" if translation.get_language_bidi() else \"ltr\",\n    }\n\n\ndef next_url(request):\n    if (\n        hasattr(request, \"path\")\n        and \"login\" not in request.path\n        and \"register\" not in request.path\n    ):\n        return {\"next_url\": request.get_full_path()}\n    return {}\n", "path": "kuma/core/context_processors.py"}]}