-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmanage.py
75 lines (66 loc) · 2.89 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! flask/bin/python
from os.path import abspath
from flask import current_app
from flask.ext.script import Manager
from flask.ext.assets import ManageAssets
from flask.ext.migrate import Migrate, MigrateCommand
from unifispot import create_app
from unifispot.extensions import db
app = create_app(mode='development')
manager = Manager(app)
manager.add_command('assets', ManageAssets())
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
#app.run(host='0.0.0.0',debug = True)
@manager.command
def init_data():
with app.app_context():
from sqlalchemy.exc import OperationalError
from flask.ext.security.utils import encrypt_password
from unifispot.models import User
from unifispot.superadmin.models import Account
from unifispot.admin.models import Admin
try:
account = Account.query.filter_by(id=1).first()
except :
app.logger.debug( "No Account table Entry found,could be running migration ")
else:
if not account:
#create default admin user
enc_pass = encrypt_password('password')
account = Account()
db.session.add(account)
admin_user = Admin(email='[email protected]',password=enc_pass,displayname= "Admin User",active=1)
admin_user.account = account
db.session.add(admin_user)
db.session.commit()
@manager.command
def demo_init():
with app.app_context():
from sqlalchemy.exc import OperationalError
from flask.ext.security.utils import encrypt_password
from unifispot.models import User
from unifispot.superadmin.models import Account
from unifispot.admin.models import Admin
from unifispot.client.models import Client
try:
account = Account.query.filter_by(id=1).first()
except :
app.logger.debug( "No Account table Entry found,could be running migration ")
else:
if not account:
#create default admin user
enc_pass = encrypt_password('password')
account = Account()
db.session.add(account)
admin_user = Admin(email='[email protected]',password=enc_pass,displayname= "Admin User1",active=1)
admin_user2 = Admin(email='[email protected]',password=enc_pass,displayname= "Admin User2",active=1)
admin_user3 = Admin(email='[email protected]',password=enc_pass,displayname= "Admin User3",active=1)
admin_user.account = account
admin_user2.account = account
admin_user3.account = account
db.session.add(admin_user)
db.session.add(admin_user2)
db.session.add(admin_user3)
db.session.commit()
manager.run()