-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
58 lines (43 loc) · 1.5 KB
/
Copy path__init__.py
File metadata and controls
58 lines (43 loc) · 1.5 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
from flask import Flask
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from .config import ApplicationConfig
from flask_login import LoginManager
db = SQLAlchemy()
mail = Mail()
def create_app():
# configure app
app = Flask(__name__, static_folder='static')
app.config.from_object(ApplicationConfig)
# Initialize the SQLAlchemy extension
db.init_app(app)
# Initialize the Mail extension
mail.init_app(app)
from .views import views
from .auth import auth
# Register all neccessary blueprints
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
from .models import User, Transaction
# Create the database tables
with app.app_context():
db.create_all()
# Initialize our login manager
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
if user_id == 'None':
# handle the case where user_id is None
# This means the user is a guest
return None
user = User.query.get(user_id)
return user
return app
def create_database(app):
"""Create database tables if they don't exist"""
with app.app_context():
if not db.engine.dialect.has_table(db.engine, 'transactions') or not db.engine.dialect.has_table(db.engine, 'users'):
db.create_all()
print('Created Database!')