Better way to initialise things on setup.

pull/38/head
Andrew Godwin 2022-11-22 17:06:32 -07:00
rodzic b7c7c66013
commit 05ed5989e3
4 zmienionych plików z 14 dodań i 10 usunięć

Wyświetl plik

@ -118,5 +118,3 @@ AUTO_ADMIN_EMAIL: Optional[str] = None
STATOR_TOKEN: Optional[str] = None
SENTRY_ENABLED = False
IN_TESTS = False

Wyświetl plik

@ -10,6 +10,8 @@ DEBUG = bool(os.environ.get("TAKAHE__SECURITY_HAZARD__DEBUG", False))
# TODO: Allow better setting of allowed_hosts, if we need to
ALLOWED_HOSTS = ["*"]
CONN_MAX_AGE = 60
### User-configurable options, pulled from the environment ###
# Secret key

Wyświetl plik

@ -3,6 +3,4 @@ from .base import * # noqa
# Fixed secret key
SECRET_KEY = "testing_secret"
IN_TESTS = True
MAIN_DOMAIN = "example.com"

Wyświetl plik

@ -1,14 +1,20 @@
from django.apps import AppConfig
from django.conf import settings
from django.db.models.signals import post_migrate
class UsersConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "users"
def ready(self) -> None:
if not settings.IN_TESTS:
# Generate the server actor keypair if needed
from users.models import SystemActor
def data_init(self, **kwargs):
"""
Runs after migrations or flushes to insert anything we need for first
boot (or post upgrade).
"""
# Generate the server actor keypair if needed
from users.models import SystemActor
SystemActor.generate_keys_if_needed()
SystemActor.generate_keys_if_needed()
def ready(self) -> None:
post_migrate.connect(self.data_init, sender=self)