Skip to content

Commit

Permalink
Use django.contrib.auth.REDIRECT_FIELD_NAME
Browse files Browse the repository at this point in the history
Allow customization, but use REDIRECT_FIELD_NAME as default.
  • Loading branch information
grahamu committed Sep 19, 2016
1 parent d16099b commit 32b7623
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion account/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import functools

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.utils.decorators import available_attrs

from account.utils import handle_redirect_to_login


def login_required(func=None, redirect_field_name="next", login_url=None):
def login_required(func=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
"""
Decorator for views that checks that the user is logged in, redirecting
to the log in page if necessary.
Expand Down
3 changes: 2 additions & 1 deletion account/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from urlparse import urlparse, urlunparse

from django.contrib import messages
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.urlresolvers import resolve, reverse
from django.http import HttpResponseRedirect, QueryDict
from django.utils import translation, timezone
Expand Down Expand Up @@ -82,7 +83,7 @@ def process_request(self, request):
messages.WARNING,
_("Your password has expired. Please save a new password.")
)
redirect_field_name = "next" # fragile!
redirect_field_name = REDIRECT_FIELD_NAME

change_password_url = reverse(settings.ACCOUNT_PASSWORD_CHANGE_REDIRECT_URL)
url_bits = list(urlparse(change_password_url))
Expand Down
4 changes: 3 additions & 1 deletion account/mixins.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import unicode_literals

from django.contrib.auth import REDIRECT_FIELD_NAME

from account.conf import settings
from account.utils import handle_redirect_to_login


class LoginRequiredMixin(object):

redirect_field_name = "next"
redirect_field_name = REDIRECT_FIELD_NAME
login_url = None

def dispatch(self, request, *args, **kwargs):
Expand Down

0 comments on commit 32b7623

Please sign in to comment.