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):
|
2018-10-06 12:35:49 +02:00
|
|
|
parser.add_argument("--file", default="kfet_wagtail_17_05")
|
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:
|
2018-10-06 12:35:49 +02:00
|
|
|
homepage = Page.objects.get(title="Welcome to your new Wagtail site!")
|
2017-05-30 20:44:30 +02:00
|
|
|
homepage.delete()
|
|
|
|
Site.objects.filter(root_page=homepage).delete()
|
|
|
|
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"])
|