2017-05-30 20:44:30 +02:00
|
|
|
from django.contrib.auth.models import Group
|
|
|
|
from django.core.management import call_command
|
|
|
|
from django.core.management.base import BaseCommand
|
2019-02-04 22:50:27 +01:00
|
|
|
from wagtail.core.models import Page, Site
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Importe des données pour Wagtail"
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2019-02-11 21:10:11 +01:00
|
|
|
parser.add_argument("--file", default="kfet_wagtail_02_19")
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
|
|
|
self.stdout.write("Import des données wagtail")
|
|
|
|
|
|
|
|
# Nettoyage des données initiales posées par Wagtail dans la migration
|
|
|
|
# wagtailcore/0002
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
Group.objects.filter(name__in=("Moderators", "Editors")).delete()
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
try:
|
2019-02-11 21:10:11 +01:00
|
|
|
homepage = Page.objects.get(pk=2)
|
|
|
|
print("home page", homepage.title)
|
|
|
|
if "Welcome" in homepage.title and "Wagtail" in homepage.title:
|
|
|
|
homepage.delete()
|
|
|
|
Site.objects.filter(root_page=homepage).delete()
|
2017-05-30 20:44:30 +02:00
|
|
|
except Page.DoesNotExist:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Import des données
|
|
|
|
# Par défaut, il s'agit d'une copie du site K-Fêt (17-05)
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
call_command("loaddata", options["file"])
|