|
|
@@ -14,6 +14,7 @@ import os
|
|
|
|
|
|
from .models import Document, DocumentVersion # Changed from Document
|
|
|
from .forms import DocumentVersionForm, DocumentCreateForm # Changed from DocumentForm
|
|
|
+from .utils import convert_media_urls_to_file_paths # NEW: Utility function for media URL conversion
|
|
|
|
|
|
@login_required
|
|
|
def document_list(request):
|
|
|
@@ -126,8 +127,10 @@ def generate_pdf(request, pk):
|
|
|
# REUSE: We can use our existing version_pdf.html template!
|
|
|
html_string = render_to_string('textdocs/version_pdf.html', {'version': latest_version})
|
|
|
|
|
|
+ html_string = convert_media_urls_to_file_paths(html_string) # NEW: Convert media URLs to file paths for WeasyPrint
|
|
|
+
|
|
|
# Generate the PDF with WeasyPrint
|
|
|
- html = HTML(string=html_string, base_url=request.build_absolute_uri())
|
|
|
+ html = HTML(string=html_string)
|
|
|
pdf = html.write_pdf()
|
|
|
|
|
|
# Create the HTTP response with the PDF file
|
|
|
@@ -151,8 +154,10 @@ def generate_version_pdf(request, pk, version_number):
|
|
|
# We'll create a dedicated PDF template for versions to keep things clean
|
|
|
html_string = render_to_string('textdocs/version_pdf.html', {'version': version})
|
|
|
|
|
|
+ html_string = convert_media_urls_to_file_paths(html_string) # Convert media URLs to file paths for WeasyPrint
|
|
|
+
|
|
|
# Generate the PDF with WeasyPrint
|
|
|
- html = HTML(string=html_string, base_url=request.build_absolute_uri())
|
|
|
+ html = HTML(string=html_string)
|
|
|
pdf = html.write_pdf()
|
|
|
|
|
|
# Create the HTTP response with the PDF file
|