Files
catops/cntmanage/flightslot/middleware.py
2025-11-19 18:20:16 +01:00

19 lines
644 B
Python

from django.shortcuts import redirect
from django.urls import reverse
from django.http import HttpRequest
class RedirectNonSuperuserFromAdminMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request: HttpRequest):
# Se l'utente è loggato, non è superuser e prova ad andare in /admin/...
if hasattr(request,"user"):
if (
request.path.startswith("/admin/") and
hasattr(request.user, 'student')
):
return redirect("/user/") # redirect automatico
return self.get_response(request)