From a10b29ac98ba535a5c2f9697c54265edd2c84a78 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 12 Nov 2026 22:56:07 +0100 Subject: refactor(core): use lowercase extension names Rename shared Flask extension singletons to conventional lowercase names and update imports throughout the application and tests to remove redundant aliases. --- webmentions_ssg/cli.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'webmentions_ssg/cli.py') diff --git a/webmentions_ssg/cli.py b/webmentions_ssg/cli.py index 0fed7dd..b0459d4 100644 --- a/webmentions_ssg/cli.py +++ b/webmentions_ssg/cli.py @@ -14,7 +14,7 @@ from sqlalchemy import inspect from sqlalchemy.exc import IntegrityError from .auth import validate_password -from .extensions import DATABASE, MAIL +from .extensions import db, mail from .models import User USERS_CLI = AppGroup("users", help="Manage users.") @@ -22,7 +22,7 @@ USERS_CLI = AppGroup("users", help="Manage users.") def _require_user(username: str): """Return a user by username or report a CLI-friendly error.""" - user = DATABASE.session.scalar(sa.select(User).where(User.username == username)) + user = db.session.scalar(sa.select(User).where(User.username == username)) if user is None: raise click.ClickException(f"User {username!r} does not exist.") return user @@ -47,14 +47,14 @@ def create_user(username: str, password: str) -> None: except ValueError as exc: raise click.ClickException(str(exc)) from exc - if DATABASE.session.scalar(sa.select(User).where(User.username == username)): + if db.session.scalar(sa.select(User).where(User.username == username)): raise click.ClickException(f"User {username!r} already exists.") - DATABASE.session.add(User(username=username, password=password)) + db.session.add(User(username=username, password=password)) try: - DATABASE.session.commit() + db.session.commit() except IntegrityError as exc: - DATABASE.session.rollback() + db.session.rollback() raise click.ClickException(f"User {username!r} already exists.") from exc click.echo(f"Created user {username!r}.") @@ -63,7 +63,7 @@ def create_user(username: str, password: str) -> None: @USERS_CLI.command("list", help="List registered users.") def list_users() -> None: """List user IDs and usernames in alphabetical order.""" - users = DATABASE.session.scalars(sa.select(User).order_by(User.username)).all() + users = db.session.scalars(sa.select(User).order_by(User.username)).all() if not users: click.echo("No users found.") return @@ -90,7 +90,7 @@ def set_user_password(username: str, password: str) -> None: user = _require_user(username) user.password = password - DATABASE.session.commit() + db.session.commit() click.echo(f"Updated password for user {username!r}.") @@ -108,8 +108,8 @@ def delete_user(username: str, yes: bool) -> None: if not yes: click.confirm(f"Delete user {username!r}?", abort=True) - DATABASE.session.delete(user) - DATABASE.session.commit() + db.session.delete(user) + db.session.commit() click.echo(f"Deleted user {username!r}.") @@ -147,7 +147,7 @@ def send_test_mail(recipient: str | None) -> None: ) try: - MAIL.send(message) + mail.send(message) except Exception as exc: raise click.ClickException(f"Could not send test email: {exc}") from exc @@ -159,7 +159,7 @@ DB_CLI = AppGroup("db", help="Handle database") def _table_names() -> set[str]: """Return existing table names without modifying the database schema.""" - with DATABASE.engine.connect() as connection: + with db.engine.connect() as connection: return set(inspect(connection).get_table_names()) -- cgit v1.3.1