Sith/core/management/commands/setup.py

45 lines
1.6 KiB
Python
Raw Normal View History

#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
#
# This file is part of the website of the UTBM Student Association (AE UTBM),
# https://ae.utbm.fr.
#
# You can find the source code of the website at https://github.com/ae-utbm/sith
#
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
# OR WITHIN THE LOCAL FILE "LICENSE"
#
#
2024-07-23 22:16:31 +00:00
from django.conf import settings
2015-12-03 17:00:08 +00:00
from django.core.management import call_command
2024-06-24 11:07:36 +00:00
from django.core.management.base import BaseCommand
2016-01-28 15:53:37 +00:00
2015-12-03 17:00:08 +00:00
class Command(BaseCommand):
2024-07-23 22:16:31 +00:00
help = "Set up the development environment."
2015-12-03 17:00:08 +00:00
def handle(self, *args, **options):
2024-07-23 22:16:31 +00:00
if not settings.DEBUG:
raise Exception("Never call this command in prod. Never.")
2024-07-26 16:19:17 +00:00
data_dir = settings.BASE_DIR / "data"
2024-07-23 22:16:31 +00:00
settings.EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"
if not data_dir.is_dir():
data_dir.mkdir()
2024-07-26 16:19:17 +00:00
db_path = settings.BASE_DIR / "db.sqlite3"
2024-07-23 22:16:31 +00:00
if db_path.exists():
call_command("flush", "--noinput")
self.stdout.write("Existing database reset")
2018-10-04 19:29:19 +00:00
call_command("migrate")
2024-07-23 22:16:31 +00:00
self.stdout.write("Add the base fixtures.")
2023-05-02 09:00:23 +00:00
call_command("populate")
2024-07-23 22:16:31 +00:00
self.stdout.write("Generate additional random fixtures")
call_command("populate_more")
self.stdout.write("Build the xapian index")
call_command("rebuild_index", "--noinput")
settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
self.stdout.write("Setup complete!")