mirror of
https://git.isptech.ru/ISPsystem/isp-maintenance.git
synced 2025-09-13 18:23:08 +02:00
Update: models now follow PEP, add connection func, example app for show all vm6 users
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user