mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 14:30:17 +02:00
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
from django.views.generic.base import View
|
|
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import redirect
|
|
from django.contrib import messages
|
|
|
|
|
|
class NightModeRedirectView(View):
|
|
SESSION_VAR = "NIGHT_MODE"
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
request.session[self.SESSION_VAR] = not self.night_mode_state(request)
|
|
return HttpResponseRedirect(request.GET.get("next", "/"))
|
|
|
|
@classmethod
|
|
def night_mode_state(cls, request):
|
|
try:
|
|
return request.session.get(cls.SESSION_VAR, False)
|
|
except AttributeError:
|
|
# Session is middleware
|
|
# Sometimes request wont have a session attribute
|
|
return False
|
|
|
|
|
|
def Generic500Redirect(request):
|
|
messages.error(
|
|
request,
|
|
"Auth encountered an error processing your request, please try again. "
|
|
"If the error persists, please contact the administrators. (500 Internal Server Error)",
|
|
)
|
|
return redirect("authentication:dashboard")
|
|
|
|
|
|
def Generic404Redirect(request, exception):
|
|
messages.error(
|
|
request,
|
|
"Page does not exist. If you believe this is in error please contact the administrators. "
|
|
"(404 Page Not Found)",
|
|
)
|
|
return redirect("authentication:dashboard")
|
|
|
|
|
|
def Generic403Redirect(request, exception):
|
|
messages.error(
|
|
request,
|
|
"You do not have permission to access the requested page. "
|
|
"If you believe this is in error please contact the administrators. (403 Permission Denied)",
|
|
)
|
|
return redirect("authentication:dashboard")
|
|
|
|
|
|
def Generic400Redirect(request, exception):
|
|
messages.error(
|
|
request,
|
|
"Auth encountered an error processing your request, please try again. "
|
|
"If the error persists, please contact the administrators. (400 Bad Request)",
|
|
)
|
|
return redirect("authentication:dashboard")
|