refactor: centraliser user, humansize et trash_count dans le context processor
user et humansize injectés via _inject_globals() pour toutes les pages. Supprime les 8 injections manuelles redondantes dans les routes. Corrige le bug : /trash n'avait pas user → header incomplet. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4442022982
commit
b85056a2fb
1 changed files with 7 additions and 10 deletions
17
app/app.py
17
app/app.py
|
|
@ -356,7 +356,12 @@ def _entry(item: Path) -> dict:
|
|||
|
||||
@app.context_processor
|
||||
def _inject_globals():
|
||||
return {"trash_count": _trash_count() if _user() else 0}
|
||||
u = _user()
|
||||
return {
|
||||
"user": u,
|
||||
"trash_count": _trash_count() if u else 0,
|
||||
"humansize": _humansize,
|
||||
}
|
||||
|
||||
|
||||
# ── Auth ──────────────────────────────────────────────────────────────
|
||||
|
|
@ -414,12 +419,10 @@ def dashboard():
|
|||
folders[item.name] = _folder_stats(item)
|
||||
|
||||
return render_template("dashboard.html",
|
||||
user=_user(),
|
||||
folders=folders,
|
||||
total_files=sum(v["files"] for v in folders.values()),
|
||||
total_size=sum(v["size"] for v in folders.values()),
|
||||
trash=_trash_stats(),
|
||||
humansize=_humansize,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -462,11 +465,9 @@ def browse(subpath=""):
|
|||
]
|
||||
|
||||
return render_template("browse.html",
|
||||
user=_user(),
|
||||
entries=entries,
|
||||
subpath=subpath,
|
||||
breadcrumb=breadcrumb,
|
||||
humansize=_humansize,
|
||||
has_hits=STATS_JSON.is_file(),
|
||||
)
|
||||
|
||||
|
|
@ -486,7 +487,6 @@ def _file_preview(path: Path, subpath: str):
|
|||
next_path = str(siblings[idx + 1].relative_to(ASSETS_ROOT)) if idx is not None and idx < len(siblings) - 1 else None
|
||||
|
||||
ctx = dict(
|
||||
user=_user(),
|
||||
subpath=subpath,
|
||||
filename=path.name,
|
||||
filesize=_humansize(stat.st_size),
|
||||
|
|
@ -567,14 +567,12 @@ def search():
|
|||
results.append(e)
|
||||
|
||||
return render_template("search.html",
|
||||
user=_user(),
|
||||
q=q,
|
||||
after=after_s,
|
||||
before=before_s,
|
||||
in_content=in_content,
|
||||
results=results,
|
||||
searched=searched,
|
||||
humansize=_humansize,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -586,7 +584,6 @@ def stats():
|
|||
if redir:
|
||||
return redir
|
||||
return render_template("stats.html",
|
||||
user=_user(),
|
||||
has_report=STATS_FILE.is_file(),
|
||||
)
|
||||
|
||||
|
|
@ -691,7 +688,7 @@ def trash_list():
|
|||
return redir
|
||||
_trash_purge(30)
|
||||
entries = _trash_list()
|
||||
return render_template("trash.html", entries=entries, humansize=_humansize)
|
||||
return render_template("trash.html", entries=entries)
|
||||
|
||||
|
||||
@app.route("/trash/raw/<path:subpath>")
|
||||
|
|
|
|||
Loading…
Reference in a new issue