modified: db.py modified: routes/journal_routes.py modified: static/css/style.css modified: static/js/main.js modified: templates/base.html modified: templates/day.html modified: templates/future.html modified: templates/index.html new file: templates/monat.html modified: templates/week.html
99 lines
2.8 KiB
Python
99 lines
2.8 KiB
Python
"""Einstiegspunkt der Flask-App. Registriert alle Blueprints."""
|
|
import json
|
|
import re
|
|
from datetime import date, datetime
|
|
|
|
from flask import Flask
|
|
from markupsafe import Markup, escape
|
|
|
|
from config import Config
|
|
from db import init_db
|
|
|
|
|
|
def create_app(config_class=Config):
|
|
app = Flask(__name__)
|
|
app.config.from_object(config_class)
|
|
|
|
# Blueprints registrieren
|
|
from routes.auth_routes import auth_bp
|
|
from routes.journal_routes import journal_bp
|
|
from routes.admin_routes import admin_bp
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(journal_bp)
|
|
app.register_blueprint(admin_bp)
|
|
|
|
# Template/Filter-Helfer in Kontext verfügbar machen
|
|
from routes.journal_routes import ref_href, ref_type_label, bullet_label
|
|
|
|
@app.context_processor
|
|
def inject_globals():
|
|
today = date.today()
|
|
return {
|
|
"now": datetime.now(),
|
|
"today_str": today.strftime("%Y-%m-%d"),
|
|
"today_month": today.strftime("%Y-%m"),
|
|
"ref_href": ref_href,
|
|
"ref_type_label": ref_type_label,
|
|
"bullet_label": bullet_label,
|
|
}
|
|
|
|
@app.template_filter("linkify")
|
|
def linkify_filter(text):
|
|
"""Macht URLs und E-Mail-Adressen im Notiztext klickbar."""
|
|
if not text:
|
|
return ""
|
|
safe = str(escape(text))
|
|
safe = re.sub(
|
|
r'(https?://[^\s<>]+)',
|
|
r'<a href="\1" target="_blank" rel="noopener">\1</a>',
|
|
safe,
|
|
)
|
|
safe = re.sub(
|
|
r'([A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,})',
|
|
r'<a href="mailto:\1">\1</a>',
|
|
safe,
|
|
)
|
|
safe = re.sub(
|
|
r'(\+?[0-9][0-9\s\-\/]{6,})',
|
|
r'<a href="tel:\1">\1</a>',
|
|
safe,
|
|
)
|
|
return Markup(safe)
|
|
|
|
@app.template_filter("refs")
|
|
def refs_filter(raw):
|
|
"""Parst die refs-Spalte (JSON) zu einer Liste von dicts."""
|
|
if not raw:
|
|
return []
|
|
if isinstance(raw, (list, dict)):
|
|
return raw if isinstance(raw, list) else [raw]
|
|
try:
|
|
data = json.loads(raw)
|
|
return data if isinstance(data, list) else []
|
|
except (ValueError, TypeError):
|
|
return []
|
|
|
|
@app.template_filter("refvalue")
|
|
def ref_value_filter(ref):
|
|
"""Liefert den anzuzeigenden Wert eines Verweises."""
|
|
if isinstance(ref, dict):
|
|
return ref.get("value", "")
|
|
return str(ref)
|
|
|
|
# Schema anlegen + Bootstrap-Admin beim ersten Start
|
|
with app.app_context():
|
|
from db import get_connection
|
|
from db_helpers import ensure_admin
|
|
init_db()
|
|
ensure_admin(app)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=8000, debug=False)
|