All UI texts and generated document texts use gettext; exports follow the user's language. Adds a check that README and PluginConfig version ranges match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
27 lines
880 B
Python
27 lines
880 B
Python
from django.utils.translation import gettext as _
|
|
|
|
|
|
class MissingDependency(Exception):
|
|
pass
|
|
|
|
|
|
def render(doc, fmt, request=None):
|
|
"""Gibt (bytes, content_type, dateiendung) zurück."""
|
|
if fmt == "docx":
|
|
from .docx import render_docx
|
|
|
|
return render_docx(doc), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx"
|
|
|
|
from .html import render_html
|
|
|
|
html = render_html(doc)
|
|
if fmt == "html":
|
|
return html, "text/html; charset=utf-8", "html"
|
|
|
|
try:
|
|
from weasyprint import HTML
|
|
except (ImportError, OSError) as e:
|
|
raise MissingDependency(_("PDF export requires WeasyPrint (pip install weasyprint + Pango): %(error)s") % {"error": e})
|
|
base_url = request.build_absolute_uri("/") if request else None
|
|
return HTML(string=html, base_url=base_url).write_pdf(), "application/pdf", "pdf"
|