chore: Initial commit
This commit is contained in:
18
app/__init__.py
Normal file
18
app/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from flask import Flask
|
||||
|
||||
from .db import init_db
|
||||
|
||||
|
||||
def create_app() -> Flask:
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
init_db(app)
|
||||
|
||||
from .routes import bp # noqa: PLC0415
|
||||
|
||||
app.register_blueprint(bp)
|
||||
|
||||
return app
|
||||
21
app/db.py
Normal file
21
app/db.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from flask import Flask
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import DeclarativeBase, scoped_session, sessionmaker
|
||||
|
||||
engine = None
|
||||
SessionLocal = None
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def init_db(app: Flask) -> None: # noqa: ARG001
|
||||
global engine, SessionLocal # noqa: PLW0603
|
||||
|
||||
engine = create_engine("sqlite:///instance/app.db", echo=True, future=True)
|
||||
SessionLocal = scoped_session(sessionmaker(bind=engine))
|
||||
|
||||
from . import models # noqa: F401, PLC0415
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
6
app/main.py
Normal file
6
app/main.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from app import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
11
app/models.py
Normal file
11
app/models.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from sqlalchemy import Integer, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from .db import Base
|
||||
|
||||
|
||||
class Drink(Base):
|
||||
__tablename__ = "drinks"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String)
|
||||
8
app/routes.py
Normal file
8
app/routes.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
bp = Blueprint("main", __name__)
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def index() -> str:
|
||||
return render_template("index.html")
|
||||
10
app/templates/index.html
Normal file
10
app/templates/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Fridge Tracker</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Fridge Tracker</h1>
|
||||
<p>Welcome. System is running.</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user