Skip to content
Snippets Groups Projects
app.py 1.99 KiB
Newer Older
from flask import Flask, send_from_directory, url_for
Alex's avatar
Alex committed

from database.db import db
from config.config import APP_NAME, ENV, get_app_config, get_static_url
Alex's avatar
Alex committed

# Create and configure our Flask app
app = Flask(__name__, static_url_path=get_static_url())
app.url_map.strict_slashes = False
app.config.from_object(get_app_config())
Alex's avatar
Alex committed

db.init_app(app)
Alex's avatar
Alex committed

# uri = os.getenv("DATABASE_URL")  # or other relevant config var
# print(uri)
Alex's avatar
Alex committed

# # if uri and uri.startswith("postgres://"):
# #     uri = uri.replace("postgres://", "postgresql://", 1)
Alex's avatar
Alex committed

# #     app.config["SQLALCHEMY_DATABASE_URI"] = uri
# #     db = SQLAlchemy(app)
Alex's avatar
Alex committed

# #     db.create_all()
Alex's avatar
Alex committed

# #     if db.session.query(User).filter_by(username="testuser").first() is not None:
# #         db.session.add(User(username='testuser', email='admin@example.com'))
# #         db.session.commit()
Alex's avatar
Alex committed

# #     if db.session.query(Entity).filter_by(username="my entity").first() is not None:
# #         db.session.add(Entity(username='my entity', email='entity@example.com'))
# #         db.session.commit()

# # else:
# #     print("No database created/linked with this application")


# Serve all static assets for the frontend
@app.route('/static/<path:path>')
def serve_static_files(path):
    return send_from_directory('static', path)


# Register all routes from the blueprints module
from blueprints.home import home_blueprint
from blueprints.auth import auth_blueprint
app.register_blueprint(home_blueprint)
app.register_blueprint(auth_blueprint)

# @app.route('/test-db')
# def test_db():
#     try:
#         rows = ""

#         for user in db.session.query(User).all():
#             rows += str(user) + " "

#         for e in db.session.query(Entity).all():
#             rows += str(e) + " "

#         print("All rows:", rows)
#         return rows
#     except:
#         return "App database error"

# Hook any custom Jinja templating functions
from config import CUSTOM_TEMPLATE_FUNCTIONS
app.jinja_env.globals.update(CUSTOM_TEMPLATE_FUNCTIONS)

if __name__ == '__main__':
    app.run()