Corretto il get_active_theme nel context_processor e nel modello
parent
7e85ebac9b
commit
1b0d20f494
|
|
@ -1,7 +1,8 @@
|
||||||
from .models import Theme
|
from .models import Theme, UserTheme
|
||||||
|
|
||||||
def get_active_theme(request):
|
def get_active_theme(request):
|
||||||
objs_manager = Theme.objects
|
objs_manager = Theme.objects
|
||||||
|
user_theme_manager = UserTheme.objects
|
||||||
objs_active_qs = objs_manager.filter(active=True)
|
objs_active_qs = objs_manager.filter(active=True)
|
||||||
objs_active_ls = list(objs_active_qs)
|
objs_active_ls = list(objs_active_qs)
|
||||||
objs_active_count = len(objs_active_ls)
|
objs_active_count = len(objs_active_ls)
|
||||||
|
|
@ -26,7 +27,7 @@ def get_active_theme(request):
|
||||||
# request = None
|
# request = None
|
||||||
user = request.user
|
user = request.user
|
||||||
try:
|
try:
|
||||||
obj = objs_active_qs.filter(user=user).first()
|
obj = user_theme_manager.filter(user=user, theme__active=True).first().theme
|
||||||
except:
|
except:
|
||||||
obj = objs_active_ls[-1]
|
obj = objs_active_ls[-1]
|
||||||
obj.set_active()
|
obj.set_active()
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ class Theme(models.Model):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_active_theme():
|
def get_active_theme():
|
||||||
objs_manager = Theme.objects
|
objs_manager = Theme.objects
|
||||||
|
user_theme_manager = UserTheme.objects
|
||||||
objs_active_qs = objs_manager.filter(active=True)
|
objs_active_qs = objs_manager.filter(active=True)
|
||||||
objs_active_ls = list(objs_active_qs)
|
objs_active_ls = list(objs_active_qs)
|
||||||
objs_active_count = len(objs_active_ls)
|
objs_active_count = len(objs_active_ls)
|
||||||
|
|
@ -81,8 +82,8 @@ class Theme(models.Model):
|
||||||
request = None
|
request = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return objs_active_qs.filter(user=user).first()
|
return user_theme_manager.filter(user=user, theme__active=True).first().theme
|
||||||
except:
|
except AttributeError as e:
|
||||||
obj = objs_active_ls[-1]
|
obj = objs_active_ls[-1]
|
||||||
obj.set_active()
|
obj.set_active()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue