-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.py
38 lines (29 loc) · 1.08 KB
/
manager.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
import os, flask
from flask_security import Security, SQLAlchemyUserDatastore
from flask_migrate import Migrate
from application import create_app, db
from admin import models
# load the .flaskenv
flask.cli.load_dotenv()
app = create_app(os.getenv("FLASK_ENV","production"))
migrate = Migrate(app, db)
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
security = Security(app, user_datastore)
# add model to flask shell
@app.shell_context_processor
def make_shell_context():
modules = dict(app=app)
modules['User'] = models.User
modules['Role'] = models.Role
modules['Post'] = models.Post
modules['Contact'] = models.Contact
return modules
if os.getenv('FLASK_ENV') == 'development':
@app.before_first_request
def before_first_request():
try:
db.session.bulk_update_mappings(models.User,[{'_password':12345678,'id':1}])
db.session.commit()
print("Update default admin_1 `password`='%s'"%str(12345678))
except:
print("!Update default admin_1 `password`='%s'"%str(12345678))