-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
54 lines (37 loc) · 1.32 KB
/
manage.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
import os
from flask_script import Manager
from app import create_app, db
from commands.seed_command import SeedCommand
from dotenv import load_dotenv
load_dotenv(dotenv_path=".flaskenv", verbose=True)
from sqlalchemy import MetaData, Table, Column, Integer, String
env = os.getenv("FLASK_ENV") or "test"
print(f"Active environment: * {env} *")
app = create_app(env)
manager = Manager(app)
app.app_context().push()
manager.add_command("seed_db", SeedCommand)
@manager.command
def run():
app.run()
@manager.command
def init_db():
print("Creating all resources.")
db.create_all()
@manager.command
def drop_all():
if input("Are you sure you want to drop all tables? (y/N)\n").lower() == "y":
print("Dropping tables...")
db.drop_all()
@manager.option('--username', help='username of the super_admin to be added')
def add_super_admin(username):
from app.user.service import UserService
user = UserService.get_by_username(username=username)
UserService.change_super_admin(user, True)
@manager.option('--username', help='username of the super_admin to be removed')
def remove_super_admin(username):
from app.user.service import UserService
user = UserService.get_by_username(username=username)
UserService.change_super_admin(user, False)
if __name__ == "__main__":
manager.run()