Contenu et mécanisme uniquement, aucun style ajouté (voir consigne du 24/09/2026) : deux nouveaux kinds de contenu (badge/carte, rendu en div brutes sans CSS), un mode SVG inline pour l'image (svg_markup, nettoyé par un nouveau sanitizer allow-list avant chaque rendu) et un fichier téléchargeable joignable à un bouton (upload/download routes, stockage sous db.support_dir). Le futur système de templates portera l'habillage visuel de ces éléments. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import os
|
|
|
|
from flask import send_from_directory
|
|
from werkzeug.exceptions import NotFound
|
|
from werkzeug.wrappers import Response
|
|
|
|
import db
|
|
import document_engine
|
|
from core.flask_app import app
|
|
|
|
|
|
@app.route("/document/<slug>/elements/<int:element_id>/download-attachment")
|
|
def document_element_download_attachment(slug: str, element_id: int) -> Response:
|
|
"""Sert le fichier joint à un bouton (voir
|
|
document_element_upload_attachment.py) sous son nom d'origine
|
|
(`download_name`), jamais sous son nom de stockage anonymisé
|
|
(`attachment_stored_name`, un UUID)."""
|
|
element = document_engine.get_document_element(slug, element_id)
|
|
if element is None:
|
|
raise NotFound
|
|
stored_name = str(element["attributes"].get("attachment_stored_name", ""))
|
|
original_filename = str(element["attributes"].get("attachment_filename", ""))
|
|
if not stored_name:
|
|
raise NotFound
|
|
return send_from_directory(
|
|
os.path.join(db.support_dir(slug), "attachments"),
|
|
stored_name,
|
|
as_attachment=True,
|
|
download_name=original_filename or stored_name,
|
|
)
|