refactor: backend cleanups

This commit is contained in:
Éloi Rivard 2023-12-25 13:22:43 +01:00
parent c362f0256f
commit d4712b7971
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
2 changed files with 7 additions and 7 deletions

View file

@ -127,7 +127,9 @@ def create_app(config=None, validate=True, backend=None):
sentry_sdk = setup_sentry(app)
try:
setup_logging(app)
setup_backend(app, backend)
backend = setup_backend(app, backend)
if app.debug:
backend.install(app.config, True)
setup_flask_converters(app)
setup_blueprints(app)
setup_jinja(app)

View file

@ -89,11 +89,10 @@ class BaseBackend:
models.register(getattr(backend_models, model_name))
def setup_backend(app, backend):
def setup_backend(app, backend=None):
if not backend:
backend_name = list(app.config.get("BACKENDS", {"memory": {}}).keys())[
0
].lower()
backend_names = list(app.config.get("BACKENDS", {"memory": {}}).keys())
backend_name = backend_names[0].lower()
module = importlib.import_module(f"canaille.backends.{backend_name}.backend")
backend_class = getattr(module, "Backend")
backend = backend_class(app.config)
@ -103,8 +102,7 @@ def setup_backend(app, backend):
g.backend = backend
app.backend = backend
if app.debug:
backend.install(app.config, True)
return backend
def available_backends():