Update: models now follow PEP, add connection func, example app for show all vm6 users

This commit is contained in:
2024-02-11 23:10:29 +09:00
parent 867cd1c022
commit f9a213fe3e
8 changed files with 1387 additions and 202 deletions

View File

@@ -1,12 +1,24 @@
import click
from db.vm6.databases import isp_database
from db.vm6.models import AuthUser
@click.group(help='access command for lazy example')
@click.option('--debug/--no-debug', default=False)
def cli(debug):
click.echo(f"Debug mode is {'on' if debug else 'off'}")
def cli():
pass
@cli.command()
def enable():
click.echo('Access granted')
@cli.command(help='show all users and their roles on platform (DEMO EXAMPLE)')
def users():
# check and init connection to db:
isp_database.connect()
# get all fields from auth_user table
# SELECT * FROM auth_user;
all_users = AuthUser.select()
# Iterate fields and print to console users' email and role
for user in all_users:
result = f'{user.email} | {user.roles[0]}'
click.echo(result)
# Close connection
isp_database.close()