Skip to content

Commit

Permalink
Redirect to the previous page on login
Browse files Browse the repository at this point in the history
Fixes #1133
  • Loading branch information
khattam2 authored and ihalaij1 committed May 6, 2024
1 parent c060f31 commit 8afbc2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions course/templatetags/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand All @@ -28,6 +30,15 @@ def get_date(cont, key):
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():
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
</li>
{% else %}
<li role="presentation">
<a href="{% url 'login' %}">
<a href="{% url 'login' %}{% login_next %}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
{% translate "LOG_IN"%}
</a>
Expand Down Expand Up @@ -218,7 +218,7 @@ <h4>{% translate "SITE" %}</h4>
</li>
{% else %}
<li>
<a href="{% url 'login' %}">
<a href="{% url 'login' %}{% login_next %}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>
{% translate "LOG_IN" %}
</a>
Expand Down

0 comments on commit 8afbc2a

Please sign in to comment.