mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 07:20:17 +02:00
Theme handling improvements
This commit is contained in:
parent
24376262f0
commit
4912f0f8f0
@ -44,6 +44,8 @@ class UserSettingsMiddleware(MiddlewareMixin):
|
|||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
||||||
# AA v4 Themes
|
# AA v4 Themes
|
||||||
|
# Null = has not been set by the user ever, dont act
|
||||||
|
# DEFAULT_THEME or DEFAULT_THEME_DARK will be used in get_theme()
|
||||||
try:
|
try:
|
||||||
if request.user.profile.theme is not None:
|
if request.user.profile.theme is not None:
|
||||||
request.session["THEME"] = request.user.profile.theme
|
request.session["THEME"] = request.user.profile.theme
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from .views import NightModeRedirectView, ThemeRedirectView
|
from .views import NightModeRedirectView
|
||||||
|
|
||||||
|
|
||||||
def auth_settings(request):
|
def auth_settings(request):
|
||||||
|
@ -193,7 +193,8 @@ DATABASES = {
|
|||||||
|
|
||||||
SITE_NAME = 'Alliance Auth'
|
SITE_NAME = 'Alliance Auth'
|
||||||
|
|
||||||
DEFAULT_THEME = "allianceauth.theme.darkly"
|
DEFAULT_THEME = "allianceauth.theme.flatly.auth_hooks.FlatlyThemeHook"
|
||||||
|
DEFAULT_THEME_DARK = "allianceauth.theme.darkly.auth_hooks.DarklyThemeHook" # Legacy AAv3 user.profile.night_mode=1
|
||||||
|
|
||||||
LOGIN_URL = 'auth_login_user' # view that handles login logic
|
LOGIN_URL = 'auth_login_user' # view that handles login logic
|
||||||
|
|
||||||
|
@ -21,8 +21,11 @@ def get_theme_from_hooks(theme, hooks):
|
|||||||
def get_theme(request):
|
def get_theme(request):
|
||||||
theme = settings.DEFAULT_THEME
|
theme = settings.DEFAULT_THEME
|
||||||
hooks = get_hooks('theme_hook')
|
hooks = get_hooks('theme_hook')
|
||||||
if request.user:
|
|
||||||
theme = request.user.profile.theme or theme
|
try:
|
||||||
|
theme = request.session.get('THEME', settings.DEFAULT_THEME_DARK if request.session.get('NIGHT_MODE', False) is True else settings.DEFAULT_THEME)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
theme_hook = get_theme_from_hooks(theme, hooks)
|
theme_hook = get_theme_from_hooks(theme, hooks)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import warnings
|
||||||
from django.views.generic.base import View
|
from django.views.generic.base import View
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
@ -33,6 +34,7 @@ class NightModeRedirectView(View):
|
|||||||
|
|
||||||
|
|
||||||
class ThemeRedirectView(View):
|
class ThemeRedirectView(View):
|
||||||
|
THEME_VAR = "THEME"
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
theme = request.POST.get('theme', settings.DEFAULT_THEME)
|
theme = request.POST.get('theme', settings.DEFAULT_THEME)
|
||||||
@ -40,6 +42,7 @@ class ThemeRedirectView(View):
|
|||||||
try:
|
try:
|
||||||
request.user.profile.theme = theme
|
request.user.profile.theme = theme
|
||||||
request.user.profile.save()
|
request.user.profile.save()
|
||||||
|
request.session[self.THEME_VAR] = theme
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user