Disable sidebar for students

This commit is contained in:
2025-11-19 18:20:16 +01:00
parent 72891440af
commit 78f53cae7d
4 changed files with 47 additions and 22 deletions

View File

@@ -0,0 +1,18 @@
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)