new
parent
473d4035f8
commit
464f8a967b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,13 +1,21 @@
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from .models import *
|
from .models import *
|
||||||
|
from django.http import QueryDict
|
||||||
|
|
||||||
def staff_login_required(view_func):
|
def staff_login_required(view_func):
|
||||||
@wraps(view_func)
|
@wraps(view_func)
|
||||||
def _wrapped_view(request, *args, **kwargs):
|
def _wrapped_view(request, *args, **kwargs):
|
||||||
# Check if the user is logged in and is a staff member
|
# Check if the user is logged in and is a staff member
|
||||||
if not request.user.is_authenticated or not StaffProfile.objects.filter(user=request.user):
|
if not request.user.is_authenticated or not StaffProfile.objects.filter(user=request.user):
|
||||||
return redirect('signout') # Redirect to login URL if not staff
|
# Capture the 'next' page
|
||||||
|
next_page = request.build_absolute_uri()
|
||||||
|
query_params = QueryDict(mutable=True)
|
||||||
|
query_params['next'] = next_page
|
||||||
|
query_string = query_params.urlencode()
|
||||||
|
login_url = f"/login/?{query_string}" # Change the login URL as per your project setup
|
||||||
|
return redirect(login_url)
|
||||||
|
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
return _wrapped_view
|
return _wrapped_view
|
Loading…
Reference in New Issue