54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
LEGO Instructions Manager
|
|
Main application entry point
|
|
"""
|
|
import os
|
|
from app import create_app, db
|
|
from app.models import User, Set, Instruction
|
|
|
|
# Create Flask application
|
|
app = create_app(os.getenv('FLASK_ENV', 'development'))
|
|
|
|
|
|
@app.shell_context_processor
|
|
def make_shell_context():
|
|
"""Make database models available in Flask shell."""
|
|
return {
|
|
'db': db,
|
|
'User': User,
|
|
'Set': Set,
|
|
'Instruction': Instruction
|
|
}
|
|
|
|
|
|
@app.cli.command()
|
|
def init_db():
|
|
"""Initialize the database."""
|
|
db.create_all()
|
|
print('Database initialized successfully!')
|
|
|
|
|
|
@app.cli.command()
|
|
def create_admin():
|
|
"""Create an admin user."""
|
|
username = input('Enter admin username: ')
|
|
email = input('Enter admin email: ')
|
|
password = input('Enter admin password: ')
|
|
|
|
if User.query.filter_by(username=username).first():
|
|
print(f'User {username} already exists!')
|
|
return
|
|
|
|
admin = User(username=username, email=email)
|
|
admin.set_password(password)
|
|
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
|
|
print(f'Admin user {username} created successfully!')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000, debug=True)
|