-
Notifications
You must be signed in to change notification settings - Fork 3
/
manage.py
59 lines (46 loc) · 1.4 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
55
56
57
58
59
from flask import Flask
from flask_security import Security
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_security.utils import hash_password
from config import config
from api.models import db
from adminlte.admin import admin_db, admins_store, Role
app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)
Security(app, admins_store)
migrate = Migrate(app, db)
admin_migrate = Migrate(app, admin_db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def recreate_db():
db.drop_all()
db.create_all()
db.session.commit()
@manager.command
def recreate_admin_db():
admin_db.drop_all()
admin_db.create_all()
admin_db.session.commit()
@manager.command
def create_admin_record():
with app.app_context():
super_admin_role = Role(name = 'superadmin')
admin_role = Role(name = 'admin')
admin_db.session.add(super_admin_role)
admin_db.session.add(admin_role)
admin_db.session.commit()
test_user = admins_store.create_user(
first_name = 'John',
last_name = 'Doe',
email = '[email protected]',
password = hash_password('admin'),
roles = [super_admin_role, admin_role]
)
admin_db.session.add(test_user)
admin_db.session.commit()
return
if __name__ == '__main__':
manager.run()