Remove post_migrate signal handler and multi db test.

This commit is contained in:
Fabio Caccamo
2022-12-03 14:01:57 +01:00
parent d62593e01b
commit 60649ac4e6
3 changed files with 24 additions and 39 deletions
-4
View File
@@ -1,5 +1,4 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.utils.translation import gettext_lazy as _
@@ -10,9 +9,6 @@ class AdminInterfaceConfig(AppConfig):
default_auto_field = "django.db.models.AutoField"
def ready(self):
from admin_interface import settings
from admin_interface.models import Theme
settings.check_installed_apps()
post_migrate.connect(Theme.post_migrate_handler, sender=self)
+6 -17
View File
@@ -9,41 +9,30 @@ from .cache import del_cached_active_theme
class Theme(models.Model):
@staticmethod
def post_migrate_handler(**kwargs):
del_cached_active_theme()
db = kwargs["using"]
Theme.get_active_theme(database=db)
@staticmethod
def post_delete_handler(**kwargs):
del_cached_active_theme()
db = kwargs["using"]
Theme.get_active_theme(database=db)
Theme.get_active_theme()
@staticmethod
def post_save_handler(instance, **kwargs):
del_cached_active_theme()
db = kwargs["using"]
if instance.active:
Theme.objects.using(db).exclude(pk=instance.pk).update(active=False)
Theme.get_active_theme(database=db)
Theme.objects.exclude(pk=instance.pk).update(active=False)
Theme.get_active_theme()
@staticmethod
def pre_save_handler(instance, **kwargs):
if instance.pk is None:
db = kwargs["using"]
try:
obj = Theme.objects.using(db).get(name=instance.name)
obj = Theme.objects.get(name=instance.name)
instance.pk = obj.pk
except Theme.DoesNotExist:
pass
@staticmethod
def get_active_theme(database=None):
objs_manager = (
Theme.objects if database is None else Theme.objects.using(database)
)
def get_active_theme():
objs_manager = Theme.objects
objs_active_qs = objs_manager.filter(active=True)
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)