|
1 | 1 | """Esup-pod Main applications.""" |
2 | 2 |
|
| 3 | +import os |
| 4 | + |
3 | 5 | from django.apps import AppConfig |
4 | 6 | from django.db.models.signals import post_migrate |
5 | 7 | from django.utils.translation import gettext_lazy as _ |
| 8 | +from django.conf import settings |
6 | 9 | from django.core.exceptions import ObjectDoesNotExist |
| 10 | +from django.core.management import call_command |
7 | 11 |
|
8 | 12 | import json |
9 | 13 |
|
| 14 | +SITE_ID = getattr(settings, "SITE_ID", 1) |
| 15 | +INSTANCE = os.getenv("POD_INSTANCE", "pod") |
| 16 | +PORT = os.getenv("POD_PORT", 8000) |
| 17 | + |
| 18 | + |
| 19 | +def load_data(sender, **kwargs): |
| 20 | + from django.contrib.sites.models import Site |
| 21 | + |
| 22 | + call_command("loaddata", "initial_data.json") |
| 23 | + |
| 24 | + domain = f"{INSTANCE}.localhost:{PORT}" |
| 25 | + site, _ = Site.objects.update_or_create(id=settings.SITE_ID) |
| 26 | + site.domain = domain |
| 27 | + site.name = domain |
| 28 | + site.save() |
| 29 | + |
10 | 30 |
|
11 | 31 | def create_missing_pages(sender, **kwargs) -> None: |
12 | 32 | """Create missing flat pages from json fixtures.""" |
@@ -72,6 +92,7 @@ def create_missing_conf(sender, **kwargs) -> None: |
72 | 92 |
|
73 | 93 | print("---> Creating missing configurations...") |
74 | 94 | json_data = [] |
| 95 | + |
75 | 96 | with open("./pod/main/fixtures/initial_data.json", encoding="utf-8") as data_file: |
76 | 97 | json_data = json.loads(data_file.read()) |
77 | 98 |
|
@@ -157,3 +178,4 @@ def ready(self): |
157 | 178 | post_migrate.connect(create_missing_conf, sender=self) |
158 | 179 | post_migrate.connect(create_missing_pages, sender=self) |
159 | 180 | post_migrate.connect(create_first_block, sender=self) |
| 181 | + post_migrate.connect(load_data, sender=self) |
0 commit comments