Skip to content
This repository
Browse code

Tweaked new staff decorator to make tests pass

  • Loading branch information...
commit 3ef1575ec3b6f73839a0620b5e61251ffe94f695 1 parent 0a0cf50
David Winterbottom codeinthehole authored
3  oscar/apps/dashboard/app.py
... ... @@ -1,6 +1,5 @@
1 1 from django.conf.urls.defaults import patterns, url, include
2   -#from django.contrib.admin.views.decorators import staff_member_required
3   -from oscar.apps.customer.decorators import staff_member_required
  2 +from oscar.views.decorators import staff_member_required
4 3
5 4 from oscar.core.application import Application
6 5 from oscar.apps.dashboard.reports.app import application as reports_app
10 oscar/views/decorators.py
@@ -2,29 +2,26 @@
2 2
3 3 from functools import wraps
4 4 from django.contrib.auth import REDIRECT_FIELD_NAME
5   -from django.core.urlresolvers import reverse
6 5
7 6
8   -def staff_member_required(view_func, login_url=None):
  7 +def staff_member_required(view_func, login_url='/accounts/login/'):
9 8 """
10 9 Decorator for views that checks that the user is logged in and is a staff
11 10 member. The user is redirected to the login page specified by *login_url*
12 11 if not authenticated.
  12 +
13 13 This decorator is based on the admin decorator provided by the the django
14 14 ``auth`` and ``admin`` packages.
15 15 """
16   - if login_url:
17   - login_url = reverse('login')
18 16
19 17 @wraps(view_func)
20 18 def _checklogin(request, *args, **kwargs):
21 19 if request.user.is_active and request.user.is_staff:
22   - # The user is a valid staff member, continue to the redirect URL
23 20 return view_func(request, *args, **kwargs)
24 21
25   - path = request.build_absolute_uri()
26 22 # If the login url is the same scheme and net location then just
27 23 # use the path as the "next" url.
  24 + path = request.build_absolute_uri()
28 25 login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
29 26 current_scheme, current_netloc = urlparse.urlparse(path)[:2]
30 27 if ((not login_scheme or login_scheme == current_scheme) and
@@ -33,4 +30,5 @@ def _checklogin(request, *args, **kwargs):
33 30
34 31 from django.contrib.auth.views import redirect_to_login
35 32 return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME)
  33 +
36 34 return _checklogin

0 comments on commit 3ef1575

Please sign in to comment.
Something went wrong with that request. Please try again.