Переглянути джерело

Tweaked new staff decorator to make tests pass

master
David Winterbottom 13 роки тому
джерело
коміт
3ef1575ec3
2 змінених файлів з 5 додано та 8 видалено
  1. 1
    2
      oscar/apps/dashboard/app.py
  2. 4
    6
      oscar/views/decorators.py

+ 1
- 2
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

+ 4
- 6
oscar/views/decorators.py Переглянути файл

@@ -2,29 +2,26 @@ import urlparse
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 staff_member_required(view_func, login_url=None):
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

Завантаження…
Відмінити
Зберегти