open-law/app/commands/__init__.py

38 lines
1.1 KiB
Python
Raw Normal View History

2023-04-20 13:10:16 +00:00
from flask import Flask
from app import models as m
from app import db, forms
from app import schema as s
def init(app: Flask):
# 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, m=m, f=forms, s=s)
if app.config["ENV"] != "production":
@app.cli.command()
2023-04-21 12:58:47 +00:00
def db_populate():
2023-04-20 13:10:16 +00:00
"""Fill DB by dummy data."""
2023-04-21 14:23:19 +00:00
from tests.db.create_dummy_data import create_dummy_data
2023-04-20 13:10:16 +00:00
2023-04-21 12:58:47 +00:00
create_dummy_data()
print("Dummy data added")
2023-04-20 13:10:16 +00:00
@app.cli.command("create-admin")
def create_admin():
"""Create super admin account"""
if m.User.query.filter_by(username=app.config["ADMIN_USERNAME"]).first():
print(
f"User with username: [{app.config['ADMIN_USERNAME']}] already exists"
)
2023-04-20 13:10:16 +00:00
return
m.User(
username=app.config["ADMIN_USERNAME"],
password=app.config["ADMIN_PASSWORD"],
).save()
print("admin created")