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):
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue