mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 07:20:17 +02:00
Merge branch 'v4theme' into 'v4.x'
Theme handling improvements See merge request allianceauth/allianceauth!1542
This commit is contained in:
commit
07e85727ea
@ -44,6 +44,8 @@ class UserSettingsMiddleware(MiddlewareMixin):
|
||||
logger.exception(e)
|
||||
|
||||
# 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:
|
||||
if request.user.profile.theme is not None:
|
||||
request.session["THEME"] = request.user.profile.theme
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.conf import settings
|
||||
from .views import NightModeRedirectView, ThemeRedirectView
|
||||
from .views import NightModeRedirectView
|
||||
|
||||
|
||||
def auth_settings(request):
|
||||
|
@ -193,7 +193,8 @@ DATABASES = {
|
||||
|
||||
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
|
||||
|
||||
|
@ -21,8 +21,11 @@ def get_theme_from_hooks(theme, hooks):
|
||||
def get_theme(request):
|
||||
theme = settings.DEFAULT_THEME
|
||||
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)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from django.views.generic.base import View
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render, redirect
|
||||
@ -33,6 +34,7 @@ class NightModeRedirectView(View):
|
||||
|
||||
|
||||
class ThemeRedirectView(View):
|
||||
THEME_VAR = "THEME"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
theme = request.POST.get('theme', settings.DEFAULT_THEME)
|
||||
@ -40,6 +42,7 @@ class ThemeRedirectView(View):
|
||||
try:
|
||||
request.user.profile.theme = theme
|
||||
request.user.profile.save()
|
||||
request.session[self.THEME_VAR] = theme
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user