prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Login should not take the user to the front page
  Common scenario: the user is browsing a particular course module. They aren’t logged in. They decide to log in, but doing so takes them to the A+ front page, from which they have to navigate back to where they were. Inconvenient.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `course/templatetags/base.py`
  Content:
  ```
  1 from datetime import datetime
  2 
  3 from django import template
  4 from django.conf import settings
  5 from django.utils.safestring import mark_safe
  6 from django.utils.text import format_lazy
  7 from django.utils.translation import get_language, gettext_lazy as _
  8 from lib.helpers import remove_query_param_from_url, settings_text, update_url_params
  9 from exercise.submission_models import PendingSubmission
  10 from site_alert.models import SiteAlert
  11 
  12 
  13 register = template.Library()
  14 
  15 
  16 def pick_localized(message):
  17     if message and isinstance(message, dict):
  18         return (message.get(get_language()) or
  19                 message.get(settings.LANGUAGE_CODE[:2]) or
  20                 list(message.values())[0])
  21     return message
  22 
  23 
  24 def get_date(cont, key):
  25     data = cont.get(key)
  26     if data and not isinstance(data, datetime):
  27         data = datetime.strptime(data, '%Y-%m-%d')
  28         cont[key] = data
  29     return data
  30 
  31 
  32 @register.simple_tag
  33 def brand_name():
  34     return mark_safe(settings.BRAND_NAME)
  35 
  36 
  37 @register.simple_tag
  38 def brand_name_long():
  39     return mark_safe(settings.BRAND_NAME_LONG)
  40 
  41 
  42 @register.simple_tag
  43 def brand_institution_name():
  44     return mark_safe(settings_text('BRAND_INSTITUTION_NAME'))
  45 
  46 
  47 @register.simple_tag
  48 def course_alert(instance):
  49     exercises = PendingSubmission.objects.get_exercise_names_if_grader_is_unstable(instance)
  50     if exercises:
  51         message = format_lazy(
  52             _('GRADER_PROBLEMS_ALERT -- {exercises}'),
  53             exercises=exercises,
  54         )
  55         return mark_safe(format_lazy('<div class="alert alert-danger sticky-alert">{message}</div>', message=message))
  56     return ''
  57 
  58 
  59 @register.simple_tag
  60 def site_alert():
  61     alerts = SiteAlert.objects.filter(status=SiteAlert.STATUS.ACTIVE)
  62     return mark_safe(
  63         ''.join(
  64             '<div class="alert alert-danger">{}</div>'.format(pick_localized(alert.alert))
  65             for alert in alerts
  66         )
  67     )
  68 
  69 
  70 @register.simple_tag
  71 def site_advert(): # pylint: disable=inconsistent-return-statements
  72     advert = settings.SITEWIDE_ADVERT
  73     if not advert or not isinstance(advert, dict):
  74         return
  75     not_before = get_date(advert, 'not-before')
  76     not_after = get_date(advert, 'not-after')
  77     if not_before or not_after:
  78         now = datetime.now()
  79         if not_before and not_before > now:
  80             return
  81         if not_after and not_after < now:
  82             return
  83     return {k: pick_localized(advert.get(k))
  84             for k in ('title', 'text', 'href', 'image')}
  85 
  86 
  87 @register.simple_tag
  88 def tracking_html():
  89     return mark_safe(settings.TRACKING_HTML)
  90 
  91 
  92 @register.filter
  93 def localized_url(path, language=None):
  94     base_url = settings.BASE_URL
  95     if base_url.endswith('/'):
  96         base_url = base_url[:-1]
  97     path = remove_query_param_from_url(path, 'hl')
  98     if not language:
  99         language = settings.LANGUAGE_CODE.split('-')[0]
  100     path = update_url_params(path, { 'hl': language })
  101     return base_url + path
  102
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/course/templatetags/base.py b/course/templatetags/base.py
  --- a/course/templatetags/base.py
  +++ b/course/templatetags/base.py
  @@ -2,6 +2,8 @@
   
   from django import template
   from django.conf import settings
  +from django.urls import resolve
  +from django.urls.exceptions import Resolver404
   from django.utils.safestring import mark_safe
   from django.utils.text import format_lazy
   from django.utils.translation import get_language, gettext_lazy as _
  @@ -28,6 +30,15 @@
           cont[key] = data
       return data
   
  +@register.simple_tag(takes_context=True)
  +def login_next(context):
  +    request = context["request"]
  +    try:
  +        matched_url_name = resolve(request.path).url_name
  +        next_path = f"?next={request.path}" if matched_url_name != 'logout' else ""
  +        return next_path
  +    except Resolver404:
  +        return ""
   
   @register.simple_tag
   def brand_name():
  
verification_info: {"golden_diff": "diff --git a/course/templatetags/base.py b/course/templatetags/base.py\n--- a/course/templatetags/base.py\n+++ b/course/templatetags/base.py\n@@ -2,6 +2,8 @@\n \n from django import template\n from django.conf import settings\n+from django.urls import resolve\n+from django.urls.exceptions import Resolver404\n from django.utils.safestring import mark_safe\n from django.utils.text import format_lazy\n from django.utils.translation import get_language, gettext_lazy as _\n@@ -28,6 +30,15 @@\n         cont[key] = data\n     return data\n \n+@register.simple_tag(takes_context=True)\n+def login_next(context):\n+    request = context[\"request\"]\n+    try:\n+        matched_url_name = resolve(request.path).url_name\n+        next_path = f\"?next={request.path}\" if matched_url_name != 'logout' else \"\"\n+        return next_path\n+    except Resolver404:\n+        return \"\"\n \n @register.simple_tag\n def brand_name():\n", "issue": "Login should not take the user to the front page\nCommon scenario: the user is browsing a particular course module. They aren\u2019t logged in. They decide to log in, but doing so takes them to the A+ front page, from which they have to navigate back to where they were. Inconvenient.\n", "before_files": [{"content": "from datetime import datetime\n\nfrom django import template\nfrom django.conf import settings\nfrom django.utils.safestring import mark_safe\nfrom django.utils.text import format_lazy\nfrom django.utils.translation import get_language, gettext_lazy as _\nfrom lib.helpers import remove_query_param_from_url, settings_text, update_url_params\nfrom exercise.submission_models import PendingSubmission\nfrom site_alert.models import SiteAlert\n\n\nregister = template.Library()\n\n\ndef pick_localized(message):\n    if message and isinstance(message, dict):\n        return (message.get(get_language()) or\n                message.get(settings.LANGUAGE_CODE[:2]) or\n                list(message.values())[0])\n    return message\n\n\ndef get_date(cont, key):\n    data = cont.get(key)\n    if data and not isinstance(data, datetime):\n        data = datetime.strptime(data, '%Y-%m-%d')\n        cont[key] = data\n    return data\n\n\n@register.simple_tag\ndef brand_name():\n    return mark_safe(settings.BRAND_NAME)\n\n\n@register.simple_tag\ndef brand_name_long():\n    return mark_safe(settings.BRAND_NAME_LONG)\n\n\n@register.simple_tag\ndef brand_institution_name():\n    return mark_safe(settings_text('BRAND_INSTITUTION_NAME'))\n\n\n@register.simple_tag\ndef course_alert(instance):\n    exercises = PendingSubmission.objects.get_exercise_names_if_grader_is_unstable(instance)\n    if exercises:\n        message = format_lazy(\n            _('GRADER_PROBLEMS_ALERT -- {exercises}'),\n            exercises=exercises,\n        )\n        return mark_safe(format_lazy('<div class=\"alert alert-danger sticky-alert\">{message}</div>', message=message))\n    return ''\n\n\n@register.simple_tag\ndef site_alert():\n    alerts = SiteAlert.objects.filter(status=SiteAlert.STATUS.ACTIVE)\n    return mark_safe(\n        ''.join(\n            '<div class=\"alert alert-danger\">{}</div>'.format(pick_localized(alert.alert))\n            for alert in alerts\n        )\n    )\n\n\n@register.simple_tag\ndef site_advert(): # pylint: disable=inconsistent-return-statements\n    advert = settings.SITEWIDE_ADVERT\n    if not advert or not isinstance(advert, dict):\n        return\n    not_before = get_date(advert, 'not-before')\n    not_after = get_date(advert, 'not-after')\n    if not_before or not_after:\n        now = datetime.now()\n        if not_before and not_before > now:\n            return\n        if not_after and not_after < now:\n            return\n    return {k: pick_localized(advert.get(k))\n            for k in ('title', 'text', 'href', 'image')}\n\n\n@register.simple_tag\ndef tracking_html():\n    return mark_safe(settings.TRACKING_HTML)\n\n\n@register.filter\ndef localized_url(path, language=None):\n    base_url = settings.BASE_URL\n    if base_url.endswith('/'):\n        base_url = base_url[:-1]\n    path = remove_query_param_from_url(path, 'hl')\n    if not language:\n        language = settings.LANGUAGE_CODE.split('-')[0]\n    path = update_url_params(path, { 'hl': language })\n    return base_url + path\n", "path": "course/templatetags/base.py"}], "after_files": [{"content": "from datetime import datetime\n\nfrom django import template\nfrom django.conf import settings\nfrom django.urls import resolve\nfrom django.urls.exceptions import Resolver404\nfrom django.utils.safestring import mark_safe\nfrom django.utils.text import format_lazy\nfrom django.utils.translation import get_language, gettext_lazy as _\nfrom lib.helpers import remove_query_param_from_url, settings_text, update_url_params\nfrom exercise.submission_models import PendingSubmission\nfrom site_alert.models import SiteAlert\n\n\nregister = template.Library()\n\n\ndef pick_localized(message):\n    if message and isinstance(message, dict):\n        return (message.get(get_language()) or\n                message.get(settings.LANGUAGE_CODE[:2]) or\n                list(message.values())[0])\n    return message\n\n\ndef get_date(cont, key):\n    data = cont.get(key)\n    if data and not isinstance(data, datetime):\n        data = datetime.strptime(data, '%Y-%m-%d')\n        cont[key] = data\n    return data\n\n@register.simple_tag(takes_context=True)\ndef login_next(context):\n    request = context[\"request\"]\n    try:\n        matched_url_name = resolve(request.path).url_name\n        next_path = f\"?next={request.path}\" if matched_url_name != 'logout' else \"\"\n        return next_path\n    except Resolver404:\n        return \"\"\n\n@register.simple_tag\ndef brand_name():\n    return mark_safe(settings.BRAND_NAME)\n\n\n@register.simple_tag\ndef brand_name_long():\n    return mark_safe(settings.BRAND_NAME_LONG)\n\n\n@register.simple_tag\ndef brand_institution_name():\n    return mark_safe(settings_text('BRAND_INSTITUTION_NAME'))\n\n\n@register.simple_tag\ndef course_alert(instance):\n    exercises = PendingSubmission.objects.get_exercise_names_if_grader_is_unstable(instance)\n    if exercises:\n        message = format_lazy(\n            _('GRADER_PROBLEMS_ALERT -- {exercises}'),\n            exercises=exercises,\n        )\n        return mark_safe(format_lazy('<div class=\"alert alert-danger sticky-alert\">{message}</div>', message=message))\n    return ''\n\n\n@register.simple_tag\ndef site_alert():\n    alerts = SiteAlert.objects.filter(status=SiteAlert.STATUS.ACTIVE)\n    return mark_safe(\n        ''.join(\n            '<div class=\"alert alert-danger\">{}</div>'.format(pick_localized(alert.alert))\n            for alert in alerts\n        )\n    )\n\n\n@register.simple_tag\ndef site_advert(): # pylint: disable=inconsistent-return-statements\n    advert = settings.SITEWIDE_ADVERT\n    if not advert or not isinstance(advert, dict):\n        return\n    not_before = get_date(advert, 'not-before')\n    not_after = get_date(advert, 'not-after')\n    if not_before or not_after:\n        now = datetime.now()\n        if not_before and not_before > now:\n            return\n        if not_after and not_after < now:\n            return\n    return {k: pick_localized(advert.get(k))\n            for k in ('title', 'text', 'href', 'image')}\n\n\n@register.simple_tag\ndef tracking_html():\n    return mark_safe(settings.TRACKING_HTML)\n\n\n@register.filter\ndef localized_url(path, language=None):\n    base_url = settings.BASE_URL\n    if base_url.endswith('/'):\n        base_url = base_url[:-1]\n    path = remove_query_param_from_url(path, 'hl')\n    if not language:\n        language = settings.LANGUAGE_CODE.split('-')[0]\n    path = update_url_params(path, { 'hl': language })\n    return base_url + path\n", "path": "course/templatetags/base.py"}]}