Corretto il get_active_theme nel context_processor e nel modello

testato-con-bdlaser
Davide Borgonovo 2022-12-27 10:43:38 +01:00
parent 7e85ebac9b
commit 1b0d20f494
2 changed files with 6 additions and 4 deletions

View File

@ -1,7 +1,8 @@
from .models import Theme
from .models import Theme, UserTheme
def get_active_theme(request):
objs_manager = Theme.objects
user_theme_manager = UserTheme.objects
objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)
@ -26,7 +27,7 @@ def get_active_theme(request):
# request = None
user = request.user
try:
obj = objs_active_qs.filter(user=user).first()
obj = user_theme_manager.filter(user=user, theme__active=True).first().theme
except:
obj = objs_active_ls[-1]
obj.set_active()

View File

@ -57,6 +57,7 @@ class Theme(models.Model):
@staticmethod
def get_active_theme():
objs_manager = Theme.objects
user_theme_manager = UserTheme.objects
objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)
@ -81,8 +82,8 @@ class Theme(models.Model):
request = None
try:
return objs_active_qs.filter(user=user).first()
except:
return user_theme_manager.filter(user=user, theme__active=True).first().theme
except AttributeError as e:
obj = objs_active_ls[-1]
obj.set_active()