forked from DRYTRIX/TimeTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (60 loc) Β· 2.15 KB
/
Copy pathapp.py
File metadata and controls
73 lines (60 loc) Β· 2.15 KB
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
#!/usr/bin/env python3
"""
Time Tracker Application Entry Point
"""
import os
from app import create_app, db
from app.models import User, Project, TimeEntry, Task, Settings, Invoice, InvoiceItem, Client
app = create_app()
@app.shell_context_processor
def make_shell_context():
"""Add database models to Flask shell context"""
return {
'db': db,
'User': User,
'Project': Project,
'TimeEntry': TimeEntry,
'Task': Task,
'Settings': Settings,
'Invoice': Invoice,
'InvoiceItem': InvoiceItem,
'Client': Client
}
@app.cli.command()
def init_db():
"""Initialize the database with tables and default data"""
from app.models import Settings, User
# Create all tables
db.create_all()
# Initialize settings if they don't exist
if not Settings.query.first():
settings = Settings()
db.session.add(settings)
db.session.commit()
print("Database initialized with default settings")
# Create admin user if it doesn't exist (first username, stripped)
admin_username = os.getenv('ADMIN_USERNAMES', 'admin').split(',')[0].strip()
if not User.query.filter_by(username=admin_username).first():
admin_user = User(username=admin_username, role='admin')
db.session.add(admin_user)
db.session.commit()
print(f"Created admin user: {admin_username}")
print("Database initialization complete!")
@app.cli.command()
def create_admin():
"""Create an admin user"""
username = input("Enter admin username: ").strip()
if not username:
print("Username cannot be empty")
return
if User.query.filter_by(username=username).first():
print(f"User {username} already exists")
return
user = User(username=username, role='admin')
db.session.add(user)
db.session.commit()
print(f"Created admin user: {username}")
# Initialize kanban columns on startup if they don't exist
# This is handled by the migration system, so we skip it here
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=os.getenv('FLASK_DEBUG', 'false').lower() == 'true')