generated from uwidcit/flaskmvc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwsgi.py
59 lines (44 loc) · 1.58 KB
/
wsgi.py
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
49
50
51
52
53
54
55
56
57
58
59
import click
from flask import Flask
from flask.cli import with_appcontext, AppGroup
from App.database import create_db
from App.main import app, migrate
from App.controllers import ( create_user, get_all_users_json, get_all_users )
# This commands file allow you to create convenient CLI commands
# for testing controllers
# This command creates and initializes the database
@app.cli.command("init", help="Creates and initializes the database")
def initialize():
create_db(app)
print('database intialized')
'''
User Commands
'''
# Commands can be organized using groups
# create a group, it would be the first argument of the comand
# eg : flask user <command>
user_cli = AppGroup('user', help='User object commands')
# Then define the command and any parameters and annotate it with the group (@)
@user_cli.command("create", help="Creates a user")
@click.argument("username", default="rob")
@click.argument("email", default="[email protected]")
@click.argument("password", default="robpass")
def create_user_command(username, email, password):
create_user(username, email, password)
print(f'{username} created!')
# this command will be : flask user create bob bobpass
@user_cli.command("list", help="Lists users in the database")
@click.argument("format", default="string")
def list_user_command(format):
if format == 'string':
print(get_all_users())
else:
print(get_all_users_json())
app.cli.add_command(user_cli) # add the group to the cli
'''
Generic Commands
'''
@app.cli.command("init")
def initialize():
create_db(app)
print('database intialized')