diff --git a/CHANGES.md b/CHANGES.md index 4d23e437..cb246e7c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ CHANGELOG 8.7.2+dev (XXXX-XX-XX) ----------------------- +**Bug fixes** + +- Fix weasyprint html public view by converting file:// schemes with http:// + + 8.7.2 (2024-03-22) ------------------- @@ -11,13 +16,15 @@ CHANGELOG - 'Others' color config to use with leaflet overlay (#290) -8.7.1 (2024-03-13) -------------------- + +8.7.1 (2024-03-13) +----------------------- **Feature** - Add current object in detail leaflet overlay (related to https://github.com/GeotrekCE/Geotrek-admin/issues/1300) + 8.7.0 (2024-02-28) ----------------------- @@ -34,7 +41,6 @@ CHANGELOG - Support sub languages (see https://github.com/GeotrekCE/Geotrek-admin/issues/3801) - 8.6.1 (2023-09-18) ----------------------- diff --git a/mapentity/tests/__init__.py b/mapentity/tests/__init__.py index 7efd0ca0..4a842a10 100644 --- a/mapentity/tests/__init__.py +++ b/mapentity/tests/__init__.py @@ -18,6 +18,7 @@ from django.test import TestCase, LiveServerTestCase from django.test.testcases import to_list from django.test.utils import override_settings +from django.urls import reverse from django.utils import html from django.utils.encoding import force_str from django.utils.http import http_date @@ -28,6 +29,7 @@ from .factories import AttachmentFactory, SuperUserFactory, UserFactory from ..forms import MapEntityForm from ..helpers import smart_urljoin +from ..models import ENTITY_MARKUP from ..settings import app_settings from paperclip.settings import get_attachment_model @@ -123,6 +125,18 @@ def test_document_export(self, mock_requests): response = self.client.get(obj.get_document_url()) self.assertEqual(response.status_code, 200) + @patch('mapentity.helpers.requests') + def test_document_markup(self, mock_requests): + if self.model is None: + return # Abstract test should not run + + mock_requests.get.return_value.status_code = 200 + mock_requests.get.return_value.content = b'
Mock
' + + obj = self.modelfactory.create() + response = self.client.get(reverse(obj._entity.url_name(ENTITY_MARKUP), args=[obj.pk])) + self.assertEqual(response.status_code, 200) + def test_bbox_filter(self): if self.model is None: return # Abstract test should not run diff --git a/mapentity/views/generic.py b/mapentity/views/generic.py index 2edf1564..1ed6f5af 100755 --- a/mapentity/views/generic.py +++ b/mapentity/views/generic.py @@ -238,6 +238,18 @@ class MapEntityMarkupWeasyprint(MapEntityWeasyprint): def get_entity_kind(cls): return mapentity_models.ENTITY_MARKUP + def patch_static_file_paths(self, content): + """ Patch weasyprint renderer content to switch file://xxx paths to html scheme """ + file_paths_media = f"file://{settings.MEDIA_ROOT}" + new_content = content.replace(file_paths_media, settings.MEDIA_URL) + file_paths_static = f"file://{settings.STATIC_ROOT}" + return new_content.replace(file_paths_static, settings.STATIC_URL) + + def render_to_response(self, context, **response_kwargs): + response = super().render_to_response(context, **response_kwargs) + response.content = self.patch_static_file_paths(response.rendered_content) + return response + class MapEntityDocumentOdt(MapEntityDocumentBase): response_class = OdtTemplateResponse