mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -1,6 +1,7 @@
|
||||
"""Core config for admin."""
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.db.models import signals
|
||||
|
||||
|
||||
BASE_EVENTS = [
|
||||
@@ -66,3 +67,5 @@ class CoreConfig(AppConfig):
|
||||
load_core_settings()
|
||||
|
||||
from . import handlers
|
||||
|
||||
signals.post_migrate.connect(handlers.create_local_config, sender=self)
|
||||
|
||||
@@ -6,8 +6,12 @@ from django.db.models.signals import post_delete
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from django.contrib.sites import models as sites_models
|
||||
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
@receiver(reversion.post_revision_commit)
|
||||
def post_revision_commit(sender, **kwargs):
|
||||
@@ -63,3 +67,11 @@ def log_object_removal(sender, instance, **kwargs):
|
||||
"user": get_request().user.username
|
||||
}
|
||||
logger.critical(msg)
|
||||
|
||||
|
||||
def create_local_config(sender, **kwargs):
|
||||
"""Create local config if needed."""
|
||||
if models.LocalConfig.objects.using(kwargs["using"]).exists():
|
||||
return
|
||||
models.LocalConfig.objects.create(
|
||||
site=sites_models.Site.objects.get_current())
|
||||
|
||||
@@ -7,13 +7,6 @@ import django.db.models.deletion
|
||||
import jsonfield.fields
|
||||
|
||||
|
||||
def create_local_config(apps, schema_editor):
|
||||
"""Create local config entry."""
|
||||
Site = apps.get_model("sites", "Site")
|
||||
LocalConfig = apps.get_model("core", "LocalConfig")
|
||||
LocalConfig.objects.create(site=Site.objects.get_current())
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
@@ -31,5 +24,4 @@ class Migration(migrations.Migration):
|
||||
('site', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sites.Site')),
|
||||
],
|
||||
),
|
||||
migrations.RunPython(create_local_config),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user