__init__.py
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import click
from flask import Blueprint
from app.models import db, User
bp = Blueprint('pdc_db', __name__)
@bp.cli.command('delete_user')
@click.argument('user_id')
def delete(user_id):
user = User.query.get(user_id)
db.session.delete(user)
db.session.commit()
@bp.cli.command('create_db')
def create():
db.create_all()
admin = User(email='admin@nowhere.org', name='admin', login='admin', password='admin')
db.session.add(admin)
db.session.commit()
@bp.cli.command('add_user')
@click.argument('email')
@click.argument('name')
@click.argument('password')
def add(email, name, password):
user = User(email=email, name=name, password=password)
db.session.add(user)
db.session.commit()
print("added ", name)
@bp.cli.command('show_all')
def show_all():
print("{:<5} {:<15} {:<15} {:<15} {:<15}".format('id', 'name', 'login', 'passwd', 'email'))
print("{:<5} {:<15} {:<15} {:<15} {:<15}".format('-' * 5, '-' * 15, '-' * 15, '-' * 15, '-' * 15))
for user in User.query.all():
print(user.login)
print("{:<5} {:<15} {:<15} {:<15} {:<15}".format(
user.id,
user.name,
user.login,
user.password,
user.email
))