OpenSlides/openslides/core/management/commands/migrate.py

30 lines
1.0 KiB
Python
Raw Normal View History

2015-01-16 14:18:34 +01:00
import os
from django.core.management.commands.migrate import Command as _Command
from ...signals import post_permission_creation
2015-01-16 14:18:34 +01:00
class Command(_Command):
"""
Migration command that does nearly the same as Django's migration command
but also calls the post_permission_creation signal.
2015-01-16 14:18:34 +01:00
"""
2019-01-06 16:22:33 +01:00
2015-01-16 14:18:34 +01:00
def handle(self, *args, **options):
from django.conf import settings
2019-01-06 16:22:33 +01:00
# Creates the folder for a SQLite3 database if necessary.
2019-01-06 16:22:33 +01:00
if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.sqlite3":
2015-01-16 14:18:34 +01:00
try:
os.makedirs(settings.OPENSLIDES_USER_DATA_PATH)
except (FileExistsError, AttributeError):
# If the folder already exists or the settings
# OPENSLIDES_USER_DATA_PATH is unknown, just do nothing.
2015-01-16 14:18:34 +01:00
pass
super().handle(*args, **options)
# Send this signal after sending post_migrate (inside super()) so that
# all Permission objects are created previously.
post_permission_creation.send(self)