-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
73 lines (54 loc) · 1.75 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/user/bin/env python
import os
import click
from app import create_app, db, models, forms, guard
from app.models import User, MessageQueue
from app.controllers import MessageSender
app = create_app()
ADMIN_FIRST_NAME = os.environ.get("ADMIN_FIRST_NAME", "Test")
ADMIN_LAST_NAME = os.environ.get("ADMIN_LAST_NAME", "Admin")
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL", "admin@default.com")
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "admin")
ADMIN_PHONE = os.environ.get("ADMIN_PHONE", "+123456789090")
def add_admin():
admin = User(
first_name=ADMIN_FIRST_NAME,
last_name=ADMIN_LAST_NAME,
email=ADMIN_EMAIL,
phone=ADMIN_PHONE,
password=guard.hash_password(ADMIN_PASSWORD),
activated=True,
roles="admin",
)
admin.save()
def _init_db():
db.create_all()
add_admin()
# flask cli context setup
@app.shell_context_processor
def get_context():
"""Objects exposed here will be automatically available from the shell."""
return dict(app=app, db=db, models=models, forms=forms)
@app.cli.command()
@click.confirmation_option(prompt="Delete all data from database tables?")
def reset_db():
"""Reset the current database."""
db.drop_all()
_init_db()
@app.cli.command()
def create_db():
"""Create the configured database."""
db.create_all()
@app.cli.command()
@click.confirmation_option(prompt="Drop all database tables?")
def drop_db():
"""Drop the current database."""
db.drop_all()
@app.cli.command()
def send_messages():
"""Activate Message Queue manager and send SMS/email messages"""
messages = MessageQueue.query.filter_by(sent=False).all()
sender = MessageSender(messages)
sender.process_messages()
if __name__ == "__main__":
app.run()