2023-04-09 14:14:38 +00:00
|
|
|
import click
|
|
|
|
from flask.cli import with_appcontext
|
|
|
|
|
2024-03-15 18:58:06 +00:00
|
|
|
from canaille.app.commands import with_backendcontext
|
|
|
|
|
2023-04-09 14:14:38 +00:00
|
|
|
try:
|
|
|
|
HAS_FAKER = True
|
2023-09-01 08:46:56 +00:00
|
|
|
except ImportError:
|
2023-04-09 14:14:38 +00:00
|
|
|
HAS_FAKER = False
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
@click.option("--nb", default=1, help="Number of items to create")
|
|
|
|
@click.pass_context
|
|
|
|
@with_appcontext
|
|
|
|
def populate(ctx, nb):
|
2023-12-28 17:31:57 +00:00
|
|
|
"""Populate the database with generated random data."""
|
2023-04-09 14:14:38 +00:00
|
|
|
ctx.ensure_object(dict)
|
|
|
|
|
|
|
|
ctx.obj["number"] = nb
|
|
|
|
|
|
|
|
|
|
|
|
@populate.command()
|
|
|
|
@click.pass_context
|
|
|
|
@with_appcontext
|
|
|
|
@with_backendcontext
|
|
|
|
def users(ctx):
|
2023-12-28 17:31:57 +00:00
|
|
|
"""Populate the database with generated random users."""
|
2023-04-09 14:14:38 +00:00
|
|
|
from canaille.core.populate import fake_users
|
|
|
|
|
|
|
|
fake_users(ctx.obj["number"])
|
|
|
|
|
|
|
|
|
|
|
|
@populate.command()
|
|
|
|
@click.pass_context
|
|
|
|
@click.option(
|
|
|
|
"--nb-users-max",
|
|
|
|
default=1,
|
|
|
|
help="The maximum number of users that will randomly be affected in the group",
|
|
|
|
)
|
|
|
|
@with_appcontext
|
|
|
|
@with_backendcontext
|
|
|
|
def groups(ctx, nb_users_max):
|
2023-12-28 17:31:57 +00:00
|
|
|
"""Populate the database with generated random groups."""
|
2023-04-09 14:14:38 +00:00
|
|
|
from canaille.core.populate import fake_groups
|
|
|
|
|
|
|
|
fake_groups(ctx.obj["number"], nb_users_max)
|
|
|
|
|
|
|
|
|
|
|
|
def register(cli):
|
|
|
|
if HAS_FAKER: # pragma: no branch
|
|
|
|
cli.add_command(populate)
|