mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
Initial commit: Flask calorie counter app setup
Add base Flask application with user authentication, SQLAlchemy models for users, units, and food items, admin blueprint, and basic templates. Includes database migration setup, login form, and seed script for initial user creation.
This commit is contained in:
18
application/__init__.py
Normal file
18
application/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from flask import Flask
|
||||
from flask_login import LoginManager # type: ignore
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from application.admin.routes import admin_bp
|
||||
|
||||
|
||||
app = Flask(__name__) # Init Flask app
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data.db"
|
||||
|
||||
|
||||
db = SQLAlchemy(app=app) # Init SQLAlchemy
|
||||
migrate = Migrate(app=app, db=db) # Init Migration
|
||||
|
||||
login_manager = LoginManager(app=app) # Init login manager
|
||||
|
||||
# Register blueprints
|
||||
app.register_blueprint(admin_bp)
|
||||
13
application/admin/routes.py
Normal file
13
application/admin/routes.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
admin_bp = Blueprint(
|
||||
"admin",
|
||||
__name__,
|
||||
url_prefix="/admin",
|
||||
template_folder="templates",
|
||||
)
|
||||
|
||||
|
||||
@admin_bp.route("/food_items", methods=["GET"])
|
||||
def food_items():
|
||||
return render_template("food_items.html")
|
||||
5
application/admin/templates/food_items.html
Normal file
5
application/admin/templates/food_items.html
Normal file
@@ -0,0 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
Hallo
|
||||
{% endblock%}
|
||||
58
application/templates/base.html
Normal file
58
application/templates/base.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}My Flask App{% endblock %}</title>
|
||||
|
||||
<!-- Bootstrap 5 CDN -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ url_for('index') }}">Iman was here</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
{% if current_user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('logout') }}">Logout</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('login') }}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('dashboard') }}">Dashboard</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
<div class="alert alert-info">
|
||||
{% for message in messages %}
|
||||
<p>{{ message }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
5
application/templates/dashboard.html
Normal file
5
application/templates/dashboard.html
Normal file
@@ -0,0 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
Hallo
|
||||
{% endblock%}
|
||||
5
application/templates/index.html
Normal file
5
application/templates/index.html
Normal file
@@ -0,0 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
Index page idk
|
||||
{% endblock%}
|
||||
10
application/templates/login.html
Normal file
10
application/templates/login.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{form.hidden_tag()}}
|
||||
{{form.username()}}
|
||||
{{form.password()}}
|
||||
{{form.submit()}}
|
||||
</form>
|
||||
{% endblock%}
|
||||
Reference in New Issue
Block a user