modified: app.py
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
This commit is contained in:
52
app.py
52
app.py
@@ -1,7 +1,10 @@
|
||||
"""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
|
||||
@@ -21,14 +24,63 @@ def create_app(config_class=Config):
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user